Loading...
Loading...
Loading...
Product prices are stored in a list. Find the highest and the lowest price and say where each one first appears (the index of its first occurrence).
Highest: <price> at index <i> and Lowest: <price> at index <j>.Example
Input
5 450 1200 90 1200 799
Output
Highest: 1200 at index 1 Lowest: 90 at index 2
The price 1200 appears twice; the first one counts.
Try the problem first. Open one hint at a time.
Collections.max(list) and Collections.min(list) find the values; indexOf finds the first position.
You can also use one index loop and compare with the best so far.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor