A survey records elevations at points on a square field. Rank all points by elevation from lowest to highest and find the elevation at the requested position. Count equal elevations separately. Negative elevations are below sea level.
int findElevation(List<String> elevations, int position)
elevations: each string represents one row of comma-separated integers, such as "-4,2,9", with no spaces.position: the 1-based rank of the required reading.sideLength = elevations.size(), where 1 ≤ sideLength ≤ 300.sideLength integers.-1,000,000,000 and 1,000,000,000, inclusive.1 ≤ position ≤ sideLength * sideLength.O(sideLength * sideLength) additional space.findElevation(elevations = List.of("-9,-1,6", "-4,3,10", "2,8,15"), position = 5)
Output: 3
The ordered readings are -9, -4, -1, 2, 3, 6, 8, 10, 15. The fifth reading is 3.
findElevation(elevations = List.of("-7,-2", "-2,5"), position = 3)
Output: -2
The ordered readings are -7, -2, -2, 5. The repeated reading -2 occupies positions 2 and 3.
findElevation(elevations = List.of("14"), position = 1)
Output: 14
There is only one survey point.