#C14537. Find Peak Element in a Matrix
Find Peak Element in a Matrix
Find Peak Element in a Matrix
You are given an \(n \times m\) matrix filled with integers. Your task is to find a peak element in the matrix. An element is considered a peak if it is not smaller than all of its adjacent neighbors. For elements on the edge or corners of the matrix, only the existing neighbors are considered.
The problem requires you to output the 0-based row and column indices of one peak element. If there are multiple peak elements, outputting the indices of any one of them is acceptable.
Note: The adjacent neighbors of an element are those directly above, below, to the left, and to the right of it.
You are encouraged to design an efficient solution. A common approach is to use a binary search style algorithm on the columns of the matrix.
inputFormat
The first line contains two integers (n) and (m), representing the number of rows and columns of the matrix respectively. This is followed by (n) lines, each containing (m) space-separated integers that represent the elements of the matrix.
outputFormat
Output two integers separated by a space: the row index and the column index of one peak element. Indices are 0-based.## sample
3 3
10 20 15
21 30 14
7 16 32
1 1