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

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

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 12
@Q-ip2km
@Q-ip2km 5 күн бұрын
Thank you! Very simple explanation
@swethavarnaau7619
@swethavarnaau7619 2 жыл бұрын
Thanks for the most simple explanation. Could you please make a separate video on the monotonic stack algorithm .. ?
@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
@Nature-pb9dh
@Nature-pb9dh 9 ай бұрын
Thank you!
@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 17 күн бұрын
// 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;
@subee128
@subee128 9 ай бұрын
Thank you very much
@ifuncuran
@ifuncuran 6 ай бұрын
"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
ROBOT ROOM CLEANER | LEETCODE # 489 | PYTHON BACKTRACK SOLUTION
19:44
Cracking FAANG
Рет қаралды 10 М.
MAKING A LARGE ISLAND | LEETCODE # 827 | PYTHON SOLUTION
22:09
Cracking FAANG
Рет қаралды 8 М.
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 135 МЛН
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 12 МЛН
ЛУЧШИЙ ФОКУС + секрет! #shorts
00:12
Роман Magic
Рет қаралды 26 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 38 МЛН
Daily Temperatures - Monotonic Stack - Leetcode 739 - Python
11:52
NESTED LIST WEIGHT SUM | LEETCODE # 339 | PYTHON BFS SOLUTION
11:00
Cracking FAANG
Рет қаралды 7 М.
ACCOUNTS MERGE | LEETCODE # 721 | PYTHON SOLUTION
23:04
Cracking FAANG
Рет қаралды 11 М.
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 359 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 506 М.
RANDOM PICK INDEX | LEETCODE # 398 | PYTHON RESERVOIR SAMPLING
14:56
Abstraction is not the enemy... lack of documentation is.
17:41
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 135 МЛН