BS-26. Find Peak Element-II | Binary Search

  Рет қаралды 65,590

take U forward

take U forward

11 ай бұрын

Problem Link: bit.ly/3Ckb4Rb
Please watch part-1: • BS-9. Find Peak Element
Notes/C++/Java/Python codes:
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
0:00 Introduction of Course

Пікірлер: 107
@iammysterious-ud9cf
@iammysterious-ud9cf 11 ай бұрын
Striver..... PLEASE CONTINUE A TO Z DSA Course....From Step 5(strings) , it is incomplete(no videos for the questions)... Your videos are very useful in intuition building and finding approach... PLEASE DONT LEAVE US IN THE MIDDLE😢😢😢...I hope you respond to the requests for the guys like me..
@bhubeshsr6281
@bhubeshsr6281 10 ай бұрын
solve by yourself - thats his intuition
@sachinchoudhary4142
@sachinchoudhary4142 10 ай бұрын
Yes please🙏🙏
@Dipanshutripathi2407
@Dipanshutripathi2407 10 ай бұрын
Yes Please
@krishnayadav5601
@krishnayadav5601 10 ай бұрын
yes please sir
@sachitkumbhat2004
@sachitkumbhat2004 10 ай бұрын
We love you Striverr!!!
@kathakalisaha9735
@kathakalisaha9735 5 ай бұрын
Those who watches your videos completely will never say you use cpp , they are the ones who dont watch the intuition part, directly jump into the code
@saibingi6980
@saibingi6980 11 ай бұрын
I request you to please make videos in Bit Manipulation, Heaps, Strings, and Disjoint-set in the upcoming sessions.
@godson200
@godson200 11 ай бұрын
He already has about 10 videos on disjoint set in the graph series. Maybe that can help.
@rekhabisht6709
@rekhabisht6709 10 ай бұрын
Phle itna khatm krle
@dumpster-jackson
@dumpster-jackson Ай бұрын
@@rekhabisht6709 Ab??
@zerobear-xf7qh
@zerobear-xf7qh 2 күн бұрын
nice solution i dont think i would come up with this solution on my own
@sundaramkumarsingh8448
@sundaramkumarsingh8448 9 ай бұрын
clear cut explanation. Thank you Striver
@securelyinsaycure
@securelyinsaycure 2 ай бұрын
Striver you are a godsend to so many of us! Thank you 🙏
@cenacr007
@cenacr007 10 ай бұрын
Array and Strings are the most important for interviews, please make a playlist on strings.
@LearnwithEase20
@LearnwithEase20 5 ай бұрын
please make videos on string and other topic it is much needed no one explains like you!🙂
@stith_pragya
@stith_pragya 5 ай бұрын
Thank You Much for this wonderful video..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@jeehub041
@jeehub041 10 ай бұрын
What an approach mind blown 🙌🙌
@anonymous-ms2en
@anonymous-ms2en Ай бұрын
love you striver ,clear explaination
@ayushagarwal5271
@ayushagarwal5271 Ай бұрын
This man is a genius!
@GeetainSaar
@GeetainSaar 8 күн бұрын
your skin glowing in whole video
@NazeerBashaShaik
@NazeerBashaShaik 3 ай бұрын
Understood, thank you.
@amanpatel6203
@amanpatel6203 11 ай бұрын
long awaited
@viveksoni3269
@viveksoni3269 2 ай бұрын
Very Nice!!!!
@utkarshtrivedi9866
@utkarshtrivedi9866 Ай бұрын
Understood, even just looking at pseudo code, I was able to code it myself.
@user-or5oz1pk2x
@user-or5oz1pk2x 3 ай бұрын
Thanks a lot Bhaiya
@AshishSingh-he2qo
@AshishSingh-he2qo 17 күн бұрын
Understood 🎉🎉
@JothiprakashThangaraj
@JothiprakashThangaraj 16 күн бұрын
sudo code is sufficient for any developer to write code in any language , understood thanks a lot !!
@binarybardic4667
@binarybardic4667 11 ай бұрын
Thanks a lot......!
@vikassinghbisht7305
@vikassinghbisht7305 3 ай бұрын
striver you are just too good
@rahulgoel7652
@rahulgoel7652 5 ай бұрын
I am unsure if first method would have O(mn *4) TC. You are traversing the matrix once, i.e. O(mn). For each element, checking the neighbors is constant time, so it wont be 4 times the number of elements
@hashcodez757
@hashcodez757 5 ай бұрын
Understood!!
@vishious14
@vishious14 6 ай бұрын
Understoood !!!!!
@ddevarapaga5134
@ddevarapaga5134 25 күн бұрын
Understood brother
@tanvirkekan6111
@tanvirkekan6111 5 ай бұрын
This is an interesting soln: x,y = 0, len(mat[0]) - 1 while x < len(mat) or y >= 0: if x + 1 < len(mat) and mat[x + 1][y] > mat[x][y]: x += 1 elif y - 1 >= 0 and mat[x][y - 1] > mat[x][y]: y -= 1 else: break return [x, y]
@shivamdubey3798
@shivamdubey3798 11 ай бұрын
Bhaiya please video continue to upload Kara Karo mera ye week topic haa🙏🙏
@anand_yv
@anand_yv 10 ай бұрын
Understood
@iammysterious-ud9cf
@iammysterious-ud9cf 11 ай бұрын
Please Start Linked Lists
@soumiyamuthuraj3516
@soumiyamuthuraj3516 13 күн бұрын
awesome
@surbhirathore._
@surbhirathore._ Ай бұрын
Done!!!
@nayankhuman1043
@nayankhuman1043 3 күн бұрын
Understood :)
@sidharthsharma341
@sidharthsharma341 11 ай бұрын
What are the upcoming topics?after this
@viratlover6206
@viratlover6206 10 ай бұрын
understood
@chandandasari6351
@chandandasari6351 10 ай бұрын
bro plzz make a videos on string problems it was missed in play list bro strivers a to Z sheet plzz upload videos
@anusmitahait2329
@anusmitahait2329 10 ай бұрын
Problem seemed so intimidating at the begining, later on was simple variation of peak.
@VishalKumar-uk5uc
@VishalKumar-uk5uc 11 ай бұрын
Ek month wait Kiya ek video ke liye
@AbdulRehman-ee8zc
@AbdulRehman-ee8zc 11 ай бұрын
sir khan thay aap aap hi k lecture ka intizar tha
@MJBZG
@MJBZG Ай бұрын
didn't really understand but will try more
@Harshitbejsbsksjnw
@Harshitbejsbsksjnw Ай бұрын
Just a little doubt, when you say we can find the maximum element in the matrix and it will surely be the peak as well. What about the fact that there can be two maximums in the matrix and both lie adjacent to each other? And the question says that the element should be strictly greater than its adjacents......
@TheAI-Tutor
@TheAI-Tutor 13 күн бұрын
But instead of traversing vertically, can't we just Traverse horizontally and find the maximum element to do STL and then check for the upper and lower element? and discard the upper half/lower half then?
@shaiksoofi3741
@shaiksoofi3741 2 ай бұрын
tq
@vijeshsshetty
@vijeshsshetty 10 ай бұрын
linked list series plss
@codeman3828
@codeman3828 6 ай бұрын
Undertsood
@adilkevin6220
@adilkevin6220 3 ай бұрын
ARTICLE column is empty for this problem. Please attach it.
@gugulothsrilakshmi8729
@gugulothsrilakshmi8729 6 ай бұрын
written article not there in description
@swagcoder
@swagcoder 11 ай бұрын
For this problem, in leetcode , it’ll fail one test case where there are multiple peaks in the same row, that one is different scenario though, in this problem it is assumed that there will be only one peak per row , because you can’t eliminate directly in case of multiple peaks.
@takeUforward
@takeUforward 11 ай бұрын
this works for it also, because even if it has multiple peaks, it will find ,watch the first video to understand why it works
@swagcoder
@swagcoder 10 ай бұрын
Thanks for replying Stiver, Understood
@guttulavybhav1030
@guttulavybhav1030 29 күн бұрын
striver please upload videos on strings it is difficult to go to others videos....
@nishantsatere9350
@nishantsatere9350 2 ай бұрын
understoddddddddd
@RitikaMajumdar__F
@RitikaMajumdar__F 5 ай бұрын
bhaiya the java cpp notes's link is not given in the description. Please do share it.
@SurajYadav-bt9jb
@SurajYadav-bt9jb Ай бұрын
I have one doubt regarding BS that it can apply on sorted ones, but here 2D Matrix is not sorted so how can we apply BS on it , please resolve my confusion
@learn_in_shorts
@learn_in_shorts 11 ай бұрын
Bhaiya mey aapka binary tree ka playlist se tree padh rha hu but jab aap iss video mey jaise padhete hai to sab samjh aata hai but tree wala mey aisa kuch samjh nahi aa rha hai jab jab aap board pr padhye jab tak to sab samjh aaya but uske baad kuch jyada nahi aaya 😊 plz bhaiya aap iss video ki format mey videos banaya kariye plz and do something trees also
@shivamkumar-hz7jt
@shivamkumar-hz7jt 11 ай бұрын
strings ke video upload krdo pls
@prikshit_sharma4071
@prikshit_sharma4071 11 ай бұрын
Bhaiya linkedlist start krdo iske badh
@saketjaiswal9381
@saketjaiswal9381 11 ай бұрын
linked list striver bhaiya
@GeetainSaar
@GeetainSaar 8 күн бұрын
give its article also
@mithileshkumbhar7968
@mithileshkumbhar7968 3 ай бұрын
Striver......The link to this problem on your page is not opening to view the code and intuition.
@AkashBisht-cq3ys
@AkashBisht-cq3ys Ай бұрын
1st july mon 9.13
@mohitsinghnitjsr2652
@mohitsinghnitjsr2652 11 ай бұрын
how many videos more to come
@charuprabha9696
@charuprabha9696 Ай бұрын
🙇‍♀🙇‍♀🙇‍♀🙇‍♀🙇‍♀🙇‍♀
@crazybro4383
@crazybro4383 3 ай бұрын
8:00
@rahulhembram4519
@rahulhembram4519 10 ай бұрын
UnderStood
@infinity2creation551
@infinity2creation551 9 ай бұрын
You are calling col ko row ...
@dhakadkumman4239
@dhakadkumman4239 14 күн бұрын
100th comment of video
@mahimagautam1810
@mahimagautam1810 10 ай бұрын
class Solution { public int findMaxIndex(int[][] mat,int mid,int n) { int maxi = -1; int ind = -1; for (int i = 0; i < n; i++) { if (mat[i][mid] > maxi) { maxi = mat[i][mid]; ind = i; } } return ind; } public int[] findPeakGrid(int[][] mat) { int ans[] = {-1,-1}; int n = mat.length; int m = mat[0].length; int low =0; int high = m-1; while(low=0 ? mat[index][mid-1]:-1; int right = mid+1left && mat[index][mid]>right){ return new int[]{index, mid}; } else if (mat[index][mid]
@harshit.53
@harshit.53 3 ай бұрын
i don't understand why people complain about only using cpp...first of all he discusses the idea behind the code and then writes a simple pseudo code...secondly, even if he uses cpp, any good coder can easily convert that code into any other language, maybe in other languages the function name and syntax is different, so u just need to use the functions provided by ur language
@daniyalhussain5231
@daniyalhussain5231 8 ай бұрын
Solution in C++: class Solution { public: int findMaxIndex(vector&mat,int col,int rows) { int maxi=INT_MIN; int maxIndex; for(int i=0;imaxi) { maxi=mat[i][col]; maxIndex=i; } } return maxIndex; } vector findPeakGrid(vector& mat) { vectorans(2); int rows=mat.size(); int cols=mat[0].size(); int low=0,high=cols-1; while(low=0)left=mat[maxElementRowIndex][mid-1];//edge case int right=-1; if(mid+1left&&curr>right) { ans[0]=maxElementRowIndex; ans[1]=mid; return ans; } else if(curr
@user-xr5tm4dk9v
@user-xr5tm4dk9v Ай бұрын
Jeetu bhaiya equivalent
@cenacr007
@cenacr007 10 ай бұрын
us
@PrinceKumar-ef1xf
@PrinceKumar-ef1xf 2 ай бұрын
vector findPeakGrid(vector& mat) { int startCol = 0, endCol = mat[0].size()-1; while(startCol = startCol+1 && mat[maxRow][midCol-1] > mat[maxRow][midCol]; bool rightIsBig = midCol mat[maxRow][midCol]; if(!leftIsBig && !rightIsBig) return vector{ maxRow, midCol}; else if(rightIsBig) startCol = midCol+1; else endCol = midCol-1; } return vector{-1,-1}; }
@Lucifer0872
@Lucifer0872 11 ай бұрын
Biltu kaka Zindabad
@adityauditsingh5986
@adityauditsingh5986 11 ай бұрын
first view xD
@dayashankarlakhotia4943
@dayashankarlakhotia4943 11 ай бұрын
public class solution { public static int []find Peek Grid(int [][]grid){ int n=grid. length,m=grid [0].length; int l=0,r=m-1; while (lgrid [idx][mid +1]){ r=mid; }else { l=mid-1; } return new int []{l,find max(grid [l])}; } public static int find max(int []col){ int index =0,n=col length; for(int i=0;icol[index]) index =i; } return index; } }; 🎉❤
@AvaneeshSrivastava-lm5vj
@AvaneeshSrivastava-lm5vj 9 ай бұрын
understood. thank you. you should sleep a bit more.
@RAJPATEL-ir7ly
@RAJPATEL-ir7ly Ай бұрын
O(n+m) BFS class Solution { public: vector findPeakGrid(vector& mat) { int i = 0 ; int j = 0 ; int n = mat.size() ; int m = mat[0].size() ; while(true){ int flag = 0 ; vector coordinates = {{1,0} , {0,1} , {-1,0} , {0,-1}} ; int maxi= -1 ; int newRow =0 ; int newCol = 0 ; for(auto coordinate : coordinates){ int x = i+coordinate.first ; int y = j+coordinate.second ; if(x>=0 && y>=0 && x
@sanjayp.m7008
@sanjayp.m7008 24 күн бұрын
why cant i use the logic of matching the row and col to mid and considering this matrix as a 2d array. i tried this but only 46 testcases passed in the leetcode qn. class Solution { public: vector findPeakGrid(vector& mat) { int n = mat.size(); int m = mat[0].size(); int low = 0; int high = n * m - 1; while (low = 0) ? mat[row][col - 1] : INT_MIN; int bottom = (row + 1 < n) ? mat[row + 1][col] : INT_MIN; int top = (row - 1 >= 0) ? mat[row - 1][col] : INT_MIN; if (el > right && el > left && el > top && el > bottom) { return {row, col}; } if (right > el) { low = mid + 1; } else if (left > el) { high = mid - 1; } else if (bottom > el) { low = mid + 1; } else { high = mid - 1; } } return {-1, -1}; } };
@ishangujarathi10
@ishangujarathi10 10 ай бұрын
why am i getting a runtime error when i submit the solution on leetcode? @striver??
@ajithc5505
@ajithc5505 8 ай бұрын
int left = mid-1>=0 ? mat[index][mid-1]:-1; int right = mid+1
@tejaswaniguttula5961
@tejaswaniguttula5961 3 ай бұрын
@@ajithc5505 Hi vector findPeakGrid(vector &g){ // Write your code here. int rows = g.size(); int cols = g[0].size(); int low = 0, high = cols-1; while(low max_ele){ max_ele = g[i][mid]; index = i; } } int left = mid-1 >= 0 ? g[index][mid-1] : -1; int right = mid +1 < cols ? g[index][mid+1] : -1; if(max_ele > left && max_ele > right){ return {index, mid}; } else if(max_ele < g[index][mid-1]){ high = mid-1; } else{ low = mid+1; } } return {-1, -1}; } }; Though I applied edge cases why I am getting runtime error for this testcase?? Test case: [[10,50,40,30,20],[1,500,2,3,4]]
@user-fu4lb7fw1t
@user-fu4lb7fw1t Ай бұрын
@@ajithc5505 thanks brother it works now
@NazeerBashaShaik
@NazeerBashaShaik 3 ай бұрын
Understood, thank you.
@user-tk2vg5jt3l
@user-tk2vg5jt3l 5 ай бұрын
Thank you Bhaiya
@_sf_editz1870
@_sf_editz1870 9 ай бұрын
Understood
@culeforever5408
@culeforever5408 9 ай бұрын
understood
@dewanandkumar8589
@dewanandkumar8589 3 ай бұрын
Understood
@abhishekprasad010
@abhishekprasad010 3 ай бұрын
Understood
@ashishpradhan6250
@ashishpradhan6250 2 ай бұрын
understood
@hardikpatel352
@hardikpatel352 3 ай бұрын
understood
@Shivi32590
@Shivi32590 3 күн бұрын
understood
BS-27. Median in a Row Wise Sorted Matrix
23:13
take U forward
Рет қаралды 79 М.
BS-9. Find Peak Element
32:53
take U forward
Рет қаралды 152 М.
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 56 МЛН
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 28 МЛН
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 45 МЛН
Launching the best DSA Course + Platform
36:29
take U forward
Рет қаралды 97 М.
Leetcode 21. Merge Two Sorted Lists [ JAVASCRIPT ].
8:43
Web Fusion with Bharadwaj
Рет қаралды 18
BS-17. Aggressive Cows | Binary Search Hard
26:44
take U forward
Рет қаралды 137 М.
L6. Single Number II | Bit Manipulation
31:19
take U forward
Рет қаралды 35 М.
L6. Job Sequencing Problem | Greedy Algorithm Playlist
16:07
take U forward
Рет қаралды 19 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 863 М.
L12. Minimum Window Substring | 2 Pointers and Sliding Window Playlist
27:06
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 56 МЛН