Skip to content

Practice Find a Peak Element II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1901
LeetCode Problem

Find a Peak Element II

Problem Statement

A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom. Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j]. You may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell. You must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.

Source: Find a Peak Element II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
mat = [[1,4],[3,2]]
Output
[0,1]

# Example 2

Input
mat = [[10,20,15],[21,30,14],[7,16,32]]
Output
[1,1]

Constraints

m == mat.length
n == mat[i].length
1 <= m, n <= 500
1 <= mat[i][j] <= 10^5
No two adjacent cells are equal.

Related LeetCode Problems

Practice more problems similar to Find a Peak Element II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.