End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS
Leetcode Problem 1901. Find a Peak Element II
1901. Find a Peak Element II
Leetcode Solutions
Binary Search on Columns
Initialize left and right pointers to the first and last column indices respectively.
Perform a binary search:
a. Calculate the mid column.
b. Find the maximum element in the mid column and its corresponding row index.
c. Check if the maximum element is a peak:
If it is greater than its left and right neighbors (or does not have them), return its position.
If the left neighbor is greater, move the right pointer to mid - 1.
If the right neighbor is greater, move the left pointer to mid + 1.
Repeat steps 2a to 2c until the left pointer is less than or equal to the right pointer.