NUMBER OF PEOPLE VISIBLE IN A QUEUE | LEETCODE # 1944 | PYTHON MONOTONIC STACK SOLUTION

  Рет қаралды 5,462

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 12
@nishanksoni8964
@nishanksoni8964 2 жыл бұрын
could u plz make video on sum of subarray ranges ? It's also a question of monotonic stack..
@crackfaang
@crackfaang 2 жыл бұрын
Sure let me add it to my work queue. Make sure to subscribe so you don’t miss the video when it comes out
@ram_luckyyy
@ram_luckyyy 2 жыл бұрын
kzbin.info/door/eOjJmGArxh1pOpa3DBTWuA this is the you tube channel they explained very well
@joydeepsarkar4774
@joydeepsarkar4774 Жыл бұрын
if anybody is looking for a Java code...here it is int n = heights.length; int[] res = new int[n]; Stack st = new Stack(); st.push(heights[n-1]); res[n-1]=0; for(int i=n-2;i>=0;i--){ int visible = 0; while(st.size()>0 && heights[i]>st.peek()){ visible++; st.pop(); res[i] = visible; } if(st.size()>0){ visible++; res[i] = visible; } st.push(heights[i]); } return res;
@sirfranciscanadianbacon1468
@sirfranciscanadianbacon1468 Ай бұрын
// stores number of visible people per person in heights array int[] answer = new int[heights.length]; // last person cannot see anyone to the right answer[heights.length - 1] = 0; // keep track of heights of people visible to the right from current person Stack heightStack = new Stack(); // push last person's height onto stack, since iterating from right to left heightStack.push(heights[heights.length - 1]); // loop from right to left starting at second to last person for (int i = heights.length - 2; i >= 0; i--) { // reset visible count to zero int visiblePeople = 0; // while people still in stack and current person is taller than next while (heightStack.size() > 0 && heights[i] > heightStack.peek()) { // current person can see next person visiblePeople++; // remove shorter person from stack, since they will be blocked by current person heightStack.pop(); } // if stack not empty after loop ends (all shorter people have been removed), // there is at least one taller or equal-height person in stack who can be seen by current person if (heightStack.size() > 0) { // account for this person being visible visiblePeople++; } // store total number of people found visible for current person answer[i] = visiblePeople; // push current person's height onto stack for next comparison heightStack.push(heights[i]); } return answer;
@swethavarnaau7619
@swethavarnaau7619 2 жыл бұрын
Thanks for the most simple explanation. Could you please make a separate video on the monotonic stack algorithm .. ?
@Q-ip2km
@Q-ip2km 25 күн бұрын
Thank you! Very simple explanation
@Nature-pb9dh
@Nature-pb9dh 9 ай бұрын
Thank you!
@ifuncuran
@ifuncuran 7 ай бұрын
"obviously we go from right to left" why?
@Anonymous____________A721
@Anonymous____________A721 2 ай бұрын
Because we want the next one, so we come from next to present, that is right to left
@subee128
@subee128 10 ай бұрын
Thank you very much
NESTED LIST WEIGHT SUM | LEETCODE # 339 | PYTHON BFS SOLUTION
11:00
Cracking FAANG
Рет қаралды 8 М.
ROBOT ROOM CLEANER | LEETCODE # 489 | PYTHON BACKTRACK SOLUTION
19:44
Cracking FAANG
Рет қаралды 11 М.
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 36 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 119 МЛН
MAKING A LARGE ISLAND | LEETCODE # 827 | PYTHON SOLUTION
22:09
Cracking FAANG
Рет қаралды 8 М.
Daily Temperatures - Monotonic Stack - Leetcode 739 - Python
11:52
ACCOUNTS MERGE | LEETCODE # 721 | PYTHON SOLUTION
23:04
Cracking FAANG
Рет қаралды 12 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 518 М.
Sliding Window Maximum - Monotonic Queue - Leetcode 239
15:46
NeetCode
Рет қаралды 264 М.
EXCLUSIVE TIME OF FUNCTIONS | LEETCODE 636 | PYTHON SOLUTION
15:42
Cracking FAANG
Рет қаралды 6 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 12 М.
VALID NUMBER | LEETCODE #65 | PYTHON SOLUTION
18:18
Cracking FAANG
Рет қаралды 6 М.
WORD LADDER | LEETCODE # 127 | PYTHON BFS SOLUTION
23:17
Cracking FAANG
Рет қаралды 1,9 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 199 М.
СДЕЛАЙ ТАК . Пульт будет работать вечно
9:39
Мужские интересы 79
Рет қаралды 148 М.
Me Charging My Phone Before Going Out
0:18
Godfrey Twins
Рет қаралды 14 МЛН
Telefonu Parçaladım!🤯
0:18
Safak Novruz
Рет қаралды 78 М.