heights, where each cell holds its height. Cells that share a side never have equal heights. Everything beyond the edge of the map is lower than any cell.
A **hilltop** is a cell strictly higher than each of its neighbours above, below, to the left and to the right. The map is guaranteed to have exactly one hilltop. Return its coordinates [row, column] (0-based).
Scanning every cell in O(m · n) is easy; try to find the hilltop in O(m log n) or O(n log m).heights=[[1, 2, 3], [8, 9, 4], [7, 6, 5]] → [1, 1]
Cell (1, 1) with height 9 is higher than all four neighbours. There is no other hilltop: every other cell has a higher neighbour.
heights=[[4, 6, 10, 7]] → [0, 2]
The map is a single row. Anything beyond the edge counts as lower than every cell, so the hilltop is 10 in column 2.
heights=[[2, 3], [5, 4], [8, 6]] → [2, 0]
heights[i][j] ≤ 10⁵heights=[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
[1, 1]
Run checks the first 3 tests in your browser. Submit checks all 44 tests on the server, hidden ones included.