Problem Statement
You are at the store purchasing some oranges, which are sold in bags. Each bag has a quantity of oranges in it, given in int[] bags. Assuming you buy no two bags with the same number of oranges, what is the maximum total oranges you end up purchasing?
Definition
- Class:
- Oranges
- Method:
- maximum
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int maximum(int[] bags)
- (be sure your method is public)
Constraints
- bags will contain between 1 and 50 elements, inclusive.
- Each element of bags will be between 1 and 10, inclusive.
Examples
{ 1, 2, 3 }Returns: 6
Since each bag has a different number of oranges, we can take all of them.{ 5, 2, 5, 3 }Returns: 10
We take a bag of 2, a bag of 3, and a bag of 5.{ 3 }Returns: 3
There's only one bag to take.{ 4, 4, 4, 4, 4, 4, 4 }Returns: 4
Since all the bags are the same size, we can only take one of them.