Problem Statement
Fred is buying a new shirt. Each shirt is described by two integers, fanciness and price.
Fred wants to buy a fancy shirt, but not too fancy, so he will never buy a shirt with the largest fanciness of all shirts. Also, although Fred doesn't mind spending money, he will never buy a shirt with the largest price of all shirts.
Other than the above two rules, Fred wants his shirt to be as fancy as possible. If multiple shirts satisfy this, he'll buy the cheapest one among them.
You will be given two int[]s, fanciness and price. Corresponding elements in the two int[]s describe one shirt.
If there is a shirt satisfying Fred's wishes, return a int[] containing exactly two elements: the fanciness and price of the shirt, in that order. If no such shirt is available, return an empty int[].
Definition
- Class:
- FancyShirt
- Method:
- whichShirt
- Parameters:
- int[], int[]
- Returns:
- int[]
- Method signature:
- int[] whichShirt(int[] fanciness, int[] price)
- (be sure your method is public)
Constraints
- fanciness will contain between 1 and 50 elements, inclusive.
- fanciness and price will contain the same number of elements.
- Each element of fanciness will be between 1 and 1000, inclusive.
- Each element of price will be between 1 and 1000, inclusive.
Examples
{ 15, 20, 25 }{ 15, 20, 25 }Returns: {20, 20 }The third shirt is too fancy and too expensive, so Fred will settle for the second one.{ 15, 25, 20 }{ 15, 20, 25 }Returns: {15, 15 }Now the second shirt is the fanciest, but the third is the most expensive.{ 5, 5 }{ 2, 10 }Returns: { }Both shirts are too fancy for Fred.{ 10, 1, 1 }{ 6, 4, 2 }Returns: {1, 2 }Of the two shirts with fanciness 1, Fred will choose the cheaper one.