Problem Statement
John has recently won a jackpot, but he doesn't need the money. He decided to share it with his friends instead. He knows how much money each of his friends has, and he will use this information to perform the distribution. While he still has money left, he will repeat the following steps:
- Choose the poorest friend. If there are multiple poorest friends, choose one of them randomly.
- Give 1 dollar to the chosen friend.
Definition
- Class:
- TheJackpotDivTwo
- Method:
- find
- Parameters:
- int[], int
- Returns:
- int[]
- Method signature:
- int[] find(int[] money, int jackpot)
- (be sure your method is public)
Constraints
- money will contain between 1 and 47 elements, inclusive.
- Each element of money will be between 1 and 1,000,000, inclusive.
- jackpot will be between 1 and 1,000,000, inclusive.
Examples
{1, 2, 3, 4}2
Returns: {2, 3, 3, 4 }First, John will give one dollar to the first friend. Then he will give another dollar to the first or the second friend.{4, 7}1
Returns: {5, 7 }Just one action here.{1}100
Returns: {101 }Just one friend here.{21, 85, 6, 54, 70, 100, 91, 60, 71}15
Returns: {21, 21, 54, 60, 70, 71, 85, 91, 100 }