#K47107. Matrix Peak Element
Matrix Peak Element
Matrix Peak Element
Given a 2D matrix of non-negative integers with dimensions n × m, a peak element is defined as an element that is not smaller than its immediate neighbors (up, down, left, right). Formally, an element \(a_{i,j}\) is a peak if it satisfies:
\( \begin{aligned} &\text{if } i > 0:\quad a_{i,j} \ge a_{i-1,j},\\ &\text{if } i 0:\quad a_{i,j} \ge a_{i,j-1},\\ &\text{if } j < m-1:\quad a_{i,j} \ge a_{i,j+1}. \end{aligned} \)
Your task is to find and output any one peak element from the matrix. If there are multiple peak elements, output the one encountered first in row-major order (from top to bottom and left to right). It is guaranteed that there is at least one peak in the matrix.
inputFormat
The first line of input contains two integers n and m denoting the number of rows and columns respectively. Each of the next n lines contains m space-separated integers representing the elements of the matrix.
outputFormat
Output a single integer representing any one peak element from the matrix.
## sample3 3
10 20 15
21 30 14
7 16 32
30