You are given a 2D array. Your task is to find the regional maxima in the array and return a 2D array of size (X * 2) where each row contains the position [i, j] of a regional maximum.
Definition of Regional Maximum:
A cell (i, j) is considered a regional maximum if:
Definition of Region:
For a cell (i, j) with value cell:
(i - cell to i + cell) * (j - cell to j + cell).(i - cell, j - cell), (i - cell, j + cell), (i + cell, j - cell) and (i + cell, j + cell).
Complete the function findRegionalMaxima in the editor.
findRegionalMaxima has the following parameter:
int[][] array: a 2D array of integers
Returns
int[][]: a 2D array where each row contains the position [i, j] of a regional maximum
array = [[3, 0, 1], [2, 0, 0], [0, 0, 0]] return = [[0, 0], [0, 2]]
The given 2D array is:
[
[3, 0, 1],
[2, 0, 0],
[0, 0, 0],
]
The cell at position [0, 0] with value 3 is a regional maximum because:
- It is not 0.
- Its region is from
[0, 0]to[3, 3](excluding corners and out-of-bounds), and it is the maximum in this region.
The cell at position [0, 2] with value 1 is a regional maximum because:
- It is not 0.
- Its region is from
[0, 1]to[1, 3](excluding corners and out-of-bounds), and it is the maximum in this region.
Therefore, the output is [[0, 0], [0, 2]].
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int[][] findRegionalMaxima(int[][] array) {
// write your code here
}