Trains the technique from
LeetCode 1901Find a Peak Element IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A height field is stored in mat, where mat[r][c] is the altitude of cell r, c. No two cells that share an edge hold the same altitude.
A cell is a summit when its altitude is strictly above the altitude of every cell sharing an edge with it. Cells on the border have fewer neighbours to beat, and everything off the edge of the field counts as lower than any cell, so a summit always exists.
Return the position of a summit as the pair [r, c]. When the field holds more than one summit, any one of them is accepted.
Aim for a routine that does not look at every cell: a running time on the order of rows * log(columns) or columns * log(rows) is expected.
Example 1
Cell 0, 1 holds 4, which is above both 1 and 3, and it is the only summit in this field.
Example 2
Cell 1, 1 holds 20 and beats 8 above it, 9 to its left and 4 to its right, so it is a summit.
Example 3
Cell 0, 0 holds 10 and beats 2 to its right and 3 below it. The cells at 0, 2 and at 2, 0 and at 2, 2 are summits too, so any of those four answers is accepted.
More than one answer is valid — return any one of them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_peak_grid(mat: list[list[int]]) -> list[int]:public int[] findPeakGrid(int[][] mat)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.