Problem Statement
NOTE: You may only submit each problem one time. If you submit more than once, your submissions may not count.
It's time to trade in that old 486 and get a faster computer. But, there are so many different choices on the market today, it is difficult to decide which machine to get. You have decided that there are 4 factors that really matter to you: CPU speed, memory size, hard disk size, and price. You would like a computer with a higher speed, a larger amount of memory, a larger hard disk, and a lower price.
You are not sure exactly which of those four factors is most important, but you know one thing for sure: if computer A has a higher speed, more memory and a larger hard disk than computer B, and is also cheaper than computer B, then computer A is definitely better than computer B. Also, if computer A is better than computer B with regard to some of those characteristics, and equal to computer B in the rest of them, then computer A is also definitely better than computer B.
For example, if computer A has a speed of 1000, a memory of size 128, a hard disk of size 80, and costs 500, it is definitely better than computer B which has a speed of 1000, a memory of size 64, a hard disk of size 80 and a cost of 550. You will be given int[]s speed, memory, disk, and price. Corresponding elements of the four int[]s represent a single computer. You are to find the indices (starting from 0) of all computers for which some other computer in the list is definitely better. You should put all of these indices in a int[] sorted in ascending order, and return that.
It's time to trade in that old 486 and get a faster computer. But, there are so many different choices on the market today, it is difficult to decide which machine to get. You have decided that there are 4 factors that really matter to you: CPU speed, memory size, hard disk size, and price. You would like a computer with a higher speed, a larger amount of memory, a larger hard disk, and a lower price.
You are not sure exactly which of those four factors is most important, but you know one thing for sure: if computer A has a higher speed, more memory and a larger hard disk than computer B, and is also cheaper than computer B, then computer A is definitely better than computer B. Also, if computer A is better than computer B with regard to some of those characteristics, and equal to computer B in the rest of them, then computer A is also definitely better than computer B.
For example, if computer A has a speed of 1000, a memory of size 128, a hard disk of size 80, and costs 500, it is definitely better than computer B which has a speed of 1000, a memory of size 64, a hard disk of size 80 and a cost of 550. You will be given int[]s speed, memory, disk, and price. Corresponding elements of the four int[]s represent a single computer. You are to find the indices (starting from 0) of all computers for which some other computer in the list is definitely better. You should put all of these indices in a int[] sorted in ascending order, and return that.
Definition
- Class:
- BadDeals
- Method:
- findBadDeals
- Parameters:
- int[], int[], int[], int[]
- Returns:
- int[]
- Method signature:
- int[] findBadDeals(int[] speed, int[] memory, int[] disk, int[] price)
- (be sure your method is public)
Constraints
- Each input will contain the same number of elements.
- Each input will contain between 2 and 50 elements, inclusive.
- Each element of speed will be between 100 and 5000, inclusive.
- Each element of memory will be between 32 and 4096, inclusive.
- Each element of disk will be between 1 and 1000, inclusive.
- Each element of price will be between 100 and 10000, inclusive.
Examples
{1000,1000}{128,64}{80,80}{500,550}Returns: {1 }This is the example from the problem statement. Computer 1 has less memory and costs more, and is equal in the other two characteristics, therefore, computer 0 is better than it.{1200,1000,1000}{128,128,64}{80,80,80}{500,500,550}Returns: {1, 2 }Computer 0 is better than both computers 1 and 2.{3000,3000,3000}{512,512,512}{140,140,140}{2100,2100,2100}Returns: { }These computers are all the same, so no one is better than any other.{845,3459,4835,134,4314}{2652,717,1567,3529,518}{375,704,337,359,790}{1072,3282,1680,1333,9972}Returns: { }No computer is definitely better than another.