Description
A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors. Given a 2D array, find any peak element and return its index.
Examples
Input:
mat = [[1,4],[3,2]]Output:
[0,1]Explanation:
4 is a peak element at [0,1].
Input:
mat = [[1]]Output:
[1]Explanation:
Minimal case with a single-element matrix.
Input:
mat = [[10,20,15],[21,30,14],[7,16,32]]Output:
[1,1]Explanation:
30 at position [1,1] is a peak element because it's greater than all its adjacent neighbors: 20 (above), 21 (left), 14 (right), and 16 (below). This demonstrates finding a peak in the interior of a 3x3 matrix.
Constraints
- •
m == mat.length - •
n == mat[i].length - •
1 ≤ m, n ≤ 500