Day 82 of 100 days dsa coding challenge
Source: Dev.to
Problem
Find the Peak Element in a 2D Matrix
GeeksforGeeks problem link
Difficulty: Medium Accuracy: 28.51%
Example
Input: mat[][] = [[10, 20, 15],
[21, 30, 14]]
Solution
class Solution:
def findPeakGrid(self, mat):
n = len(mat)
m = len(mat[0])
l, r = 0, m - 1
while l mat[max_row][mid]:
max_row = i
left = mat[max_row][mid-1] if mid-1 >= 0 else float('-inf')
right = mat[max_row][mid+1] if mid+1 = left and mat[max_row][mid] >= right:
return [max_row, mid]
elif left > mat[max_row][mid]:
r = mid - 1
else:
l = mid + 1
return [-1, -1]