#C11412. Peak Elements in a Matrix

    ID: 40726 Type: Default 1000ms 256MiB

Peak Elements in a Matrix

Peak Elements in a Matrix

Problem Statement: Given a matrix of integers, you are required to find all the peak elements in the matrix. An element is considered a peak if none of its adjacent neighbors (top, bottom, left, right) is strictly greater than it. For boundary elements, only existing neighbors are considered.

You must output the peak elements in the order they are encountered when traversing the matrix in row-major order.

Note: If two or more elements are equal to each other, they may all be considered peak elements if they satisfy the condition relative to their available neighbors.

inputFormat

Input Format:

  • The first line contains two space-separated integers r and c, representing the number of rows and columns respectively.
  • This is followed by r lines, each containing c space-separated integers representing the rows of the matrix.

outputFormat

Output Format:

  • Output a single line containing the peak elements found in the matrix, separated by a single space.
## sample
3 3
10 20 15
21 30 14
7 16 32
30 32