Interview Questions/Coding/Signal Peak Locator

Signal Peak Locator

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Signal Peak Locator

A signal heatmap is stored as a rectangular matrix. A cell is a strict peak if every existing vertical or horizontal neighbor has a smaller value. The heatmap is guaranteed to contain at least one strict peak. If several peaks exist, return the lexicographically first one, meaning the smallest row index, and among those, the smallest column index. Input Format: You are given a 2D integer array grid. Output Format: Return an array [row, col] identifying the lexicographically first strict peak.

Examples

Example 1
Input:
grid = [[1, 4], [3, 2]]
Output:
0 1

Explanation: Cell (0, 1) has value 4. It is greater than grid[1][1]=2, grid[0][0]=1, so (0, 1) is a valid peak.

Approach hint

Look for the state that actually matters after each operation.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp