Find the Peak Element in a 2D Matrix | GFG POTD | Binary Search | Java
Автор: The Optimal Approach
Загружено: 2025-12-25
Просмотров: 44
In this video, we solve GeeksforGeeks Problem of the Day – Find the Peak Element in a 2D Matrix using Binary Search in Java.
🔹 Problem Statement
You are given:
A 2D matrix mat[][]
An element is considered a peak if it is greater than or equal to its four neighbors (top, bottom, left, right)
For boundary cells, missing neighbors are treated as negative infinity
Multiple peak elements may exist — return any one of them
🔹 Optimized Approach Used
1. Traverse each row of the matrix
2. Apply Binary Search on columns to locate a candidate peak
3. For the mid element:
Compare with top, bottom, left, and right neighbors
If it satisfies the peak condition → return its position
4. Otherwise:
Move towards the direction of the greater neighbor
📌 Time Complexity:
O(*n log m*)
n → number of rows
m → number of columns
📌 Space Complexity:
constant space O(1) (excluding output list)
🔹 Resources
Problem Link: https://www.geeksforgeeks.org/problem...
Code Link: https://github.com/sibasundarj8/java-...
👉 This problem is a classic application of binary search in 2D matrices and is frequently asked in interviews.
👍 Like | 💬 Comment | 🔔 Subscribe for daily GFG POTD solutions in Java
#gfgpotd #geeksforgeekspotd #gfgproblemoftheday #peakelement
#2dmatrix #binarysearch #gfgdailyproblem #javadsa #dsainjava
#matrixproblems #interviewpreparation #codinginterview
#competitiveprogramming #dailydsapractice #java #gfgpractice
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: