Leetcode Visualized: 739. Daily Temperatures

  Рет қаралды 21,247

Alexander Le

Alexander Le

Күн бұрын

Пікірлер: 79
@jagadish3829
@jagadish3829 Жыл бұрын
man where have u been all these times ❣❣❣
@MortalWombat22
@MortalWombat22 4 ай бұрын
Still a GOATED video, helping thousands of others 4 years later!
@iiimiiim
@iiimiiim Жыл бұрын
Amazing! Thank you so much for this😍
@pi_nheiro7
@pi_nheiro7 9 ай бұрын
Thank you so much, you explain very well!!
@KushalBhatia
@KushalBhatia 4 жыл бұрын
This world need more people like you. Thank you for all the efforts you took to make this video 🙏👍
@powerhead
@powerhead 3 жыл бұрын
Thanks for great visualisation! Small optimization. No need to store tuples in the stack, its enough to store only indexes and get values from T by these indexes. And also no need to do additional comparison on line 15 since stack at this point contain only values greater than current day temperature. public int[] warmDays(int[] days) { result = new int[days.length]; Stack stack = new Stack(); for(int day = days.length-1; day >= 0; day--) { while (!stack.isEmpty() && days[stack.peek()]
@amruthammohan1667
@amruthammohan1667 2 жыл бұрын
Just amazing...❣
@kaitlinzhang1378
@kaitlinzhang1378 10 ай бұрын
Awesome explanation with great visualizations -- thanks so much for putting this together!
@viridianite
@viridianite 2 ай бұрын
Thanks a lot, Alexander! I had seen another similar implementation where you start at the beginning of the array but while I understood the code, I couldn't wrap my head around it and wouldn't have been able to simulate the algorithm with pen and paper. That walkthrough visualization was top notch, keep it up! 15:00 By the way, I think that in this conditional statement you don't need "T[i] < stack[stack.length - 1][0]" given that you already established it with "T[i] >= stack[stack.length - 1][0]" in the while loop. Assuming the stack isn't empty, after all that popping, the day at the stack's top is guaranteed to be warmer than the current day at index i so there's no need to test for it.
@nikhilmishra7572
@nikhilmishra7572 3 жыл бұрын
As soon as I saw the stack visual I clicked subscribe button! Great job!
@BS-eu9do
@BS-eu9do 2 жыл бұрын
Thanks for great visualisation!
@haifzhan
@haifzhan 3 жыл бұрын
Good explanation and I like the way you drag the next pointer!
@arpansen423
@arpansen423 4 жыл бұрын
Thank you, this is the best way to teach algorithms, pl. keep uploading videos regularly
@zhenlinjin3142
@zhenlinjin3142 3 жыл бұрын
Thanks a lot for your analysis! The use of array is great because it defaults the empty values to 0, in our case we won't have to manually do for cases when warmer temp is not found.
@captain_knoxx
@captain_knoxx Жыл бұрын
One of the best leetcode explanation videos I have ever seen. Shame you stopped recording them :(
@rahoolification
@rahoolification 4 жыл бұрын
Keep up the good work my friend. Really appreciate it!!!
@spacesuitred3839
@spacesuitred3839 4 жыл бұрын
Amazing explanation and drawing!
@omarflores4234
@omarflores4234 3 жыл бұрын
Im speechless! This was a fantastic explanation! As others have pointed out, visualizing these kinds of problems is the key to understanding them. Thank you very much and keep up the good work!
@xmaxfuture
@xmaxfuture 4 жыл бұрын
Thank you so much Alexander
@AmanRaj-gy6qv
@AmanRaj-gy6qv 2 жыл бұрын
Thank you for visualisation, understood the concepts well enough
@sk45861
@sk45861 Жыл бұрын
why do we have to walk from last when you can walk the array from the first? e.g for (let i = 0; i < temperatures.length; i++) { while (stack.length && temperatures[stack[stack.length - 1]] < temperatures[i]) { const j = stack.pop()!; result[j] = i - j; // calculate the number of days until a warmer temperature } stack.push(i); // push current index onto the stack for future comparisons } return result;
@viridianite
@viridianite 2 ай бұрын
For me, walking the array from the back makes the implementation a lot similar to the way Alexander explained the algorithm, and thus more intuitive to think about it. I.e.: Declare a stack; also declare a result array initialized to 0. Starting from end of the input array, for every temperature at index i: 1. While the stack isn't empty and current temperature at i is warmer (i.e., greater than or equal to) than the temperature at stack's top index, pop the stack. 2. If the stack isn't empty, then we found a warmer day. The number of days till warmer for index i in result array is stack's top index minus current index i. 3. Push current index into the stack. Return result array.
@SimplyaGameAholic
@SimplyaGameAholic 4 жыл бұрын
you deserve a big blue nice like my friend
@saladHz
@saladHz 2 ай бұрын
Welp this example really helped just sucked that it began from the end of the list rather than the beginning
@maheiramkhan
@maheiramkhan 4 жыл бұрын
Amazing, truly! This visualization helped me so much! I had read so many solutions but couldn't understand. Your visualization made it so easy! Thanks so much.
@poyanimehta9746
@poyanimehta9746 4 жыл бұрын
Great Explanation Looking for more such videos
@sase1017
@sase1017 3 жыл бұрын
Great job , but Time and Space analysis?
@shanmukhpatel
@shanmukhpatel 4 жыл бұрын
Excellent visual presentation! Thank you!
@VenkateshReddyMunagala
@VenkateshReddyMunagala 3 жыл бұрын
Wow! A very with no dislikes and very rightly so. Great Visual demonstration and explanation!
@Abhinavkmr
@Abhinavkmr 2 жыл бұрын
Thank You!
@snehaashishgupta1254
@snehaashishgupta1254 3 жыл бұрын
Sir, thanking you heartily for making such illustrative videos... please make more such videos on the remaining problems that require more visualization... gosh this channel's so underrated deserves a million views...
@ahmedouyahya
@ahmedouyahya 4 жыл бұрын
very beautiful visualization, and clear explanation. Thank you so much.
@alexromero3274
@alexromero3274 3 жыл бұрын
This was perfect! Thank you for your visualized videos. They are a huge help for visual learners!! :-)
@knowledge_wings
@knowledge_wings 4 жыл бұрын
please make more video ur stuff is wonderful
@chetanshrivastava3762
@chetanshrivastava3762 4 жыл бұрын
Very nice explanation with visual graphics...
@neelpawar3340
@neelpawar3340 3 жыл бұрын
This was so good!
@SiddharthMathur2k007
@SiddharthMathur2k007 3 жыл бұрын
Thank You! :)
@하이-x1i
@하이-x1i 3 жыл бұрын
Finally I can understand!!! thx!!!
@DrSeanKennedy-k2b
@DrSeanKennedy-k2b 4 жыл бұрын
Excellent explanation and use of visuals. Where needed I love to use a whiteboard. Subscribed and liked.
@MrDheeraj14
@MrDheeraj14 4 жыл бұрын
Very Well explained :) Really appreciate your efforts! Just a quick change suggestion at line 12: There should not be a equal to, =, check, otherwise it will not pass [89,62,70,58,47,47,46,76,100,70] case. because 47, 47 is repeating element and equal to condition will remove the 47 at 5th index.
@akshdeeprajawat9642
@akshdeeprajawat9642 3 жыл бұрын
Wooooooooooow !
@kc8478
@kc8478 4 жыл бұрын
very cool
@manojg4451
@manojg4451 4 жыл бұрын
Plzzzzz do more videos ,With this kind of explanation,you will be the to-go channel for leetcode
@paulomarques8147
@paulomarques8147 4 жыл бұрын
Nice explanation. Subscibed. :+1: Just a note: You could remove the second validation in line 15, as if T[i] was not lower than the elements in the stack, the stack would be empty in that case.
@kaushiktummalapali4000
@kaushiktummalapali4000 4 жыл бұрын
Thanks a ton! Way better explanation than leet code solution break through!
@keller8064
@keller8064 4 жыл бұрын
Thanks this has been helpful! Also, one thing we can do is instead of pushing the value as well as the index, we can only push the index in an integer array, thus, saving us from making the type array. Here's my C++ code vector dailyTemperatures(vector& T) { vector st; vector ans(T.size(), 0); st.push_back(T.size()-1); for(int i=T.size()-2; i>=0; i--) { while(!st.empty() && T[i] >= T[st.back()]) st.pop_back(); if(!st.empty() && T[i] < T[st.back()]) ans[i] = st.back() - i; st.push_back(i); } return ans; }
@yeqinghuang2117
@yeqinghuang2117 4 жыл бұрын
Thank you. The visualization is super helpful.
@mojo_code
@mojo_code 4 жыл бұрын
Fantastic job
@metin2dare
@metin2dare 2 жыл бұрын
ty for sharing
@peddivarunkumar
@peddivarunkumar 3 жыл бұрын
Thanks!
@yashSharma-pe1dp
@yashSharma-pe1dp 4 жыл бұрын
sir please upload visualization of other leetcode problems, coz you teaches very well!!
@SeadoooRider
@SeadoooRider 4 жыл бұрын
Thanks for the explanation. Great video. Keep doing.
@samriniqbal5096
@samriniqbal5096 4 жыл бұрын
This is so cool.
@tunabozkurt5578
@tunabozkurt5578 4 жыл бұрын
Very well done. Thanks.
@chaitanyapatil6839
@chaitanyapatil6839 3 жыл бұрын
Amazing
@abdallahelkasass6332
@abdallahelkasass6332 4 жыл бұрын
thank you very very much
@wesammustafa9004
@wesammustafa9004 4 жыл бұрын
Excellent Explanation
@ash2012ash
@ash2012ash 3 жыл бұрын
very well explained. Thanks for making me understand this question.
@Nickel80
@Nickel80 4 жыл бұрын
That was a great explanation. Thank you
@kangniliu7992
@kangniliu7992 4 жыл бұрын
Subscribed!! Awesome explanation!
@niveenelkhazendar4482
@niveenelkhazendar4482 3 жыл бұрын
Really thanks a lot for your explanation, it halp me very much
@ankitufl
@ankitufl 4 жыл бұрын
Great explanation
@avneetsng
@avneetsng 4 жыл бұрын
thanks dude
@sharmilabaskaran7373
@sharmilabaskaran7373 4 жыл бұрын
Thankyou. Please do more leetcode questions
@MangoDrankE
@MangoDrankE 4 жыл бұрын
Great explanation. Thank you!
@aliceoioih8471
@aliceoioih8471 3 жыл бұрын
Thank you for sharing! I think it'd be better if without the background music
@Noname-wp6zt
@Noname-wp6zt 4 жыл бұрын
Great explanation!
@kingjohnkk
@kingjohnkk 4 жыл бұрын
a very very good explanation and conceptual walkthrough. Didnt have to watch the rest of the video, thats how good the explanation was. Still gonna finish the video - even after having already submitted the answer :)
@aleyummusic
@aleyummusic 4 жыл бұрын
What are some other problems similar to this?
@XXXX-ib1vt
@XXXX-ib1vt 4 жыл бұрын
Is this the Corpse of Leetcode?
@chankwongyin7455
@chankwongyin7455 2 жыл бұрын
best
@namaratasharma5417
@namaratasharma5417 3 жыл бұрын
Hi, Awsm explanation ..would like to know the tool you are using for visualization
@shivanshsuhane8788
@shivanshsuhane8788 4 жыл бұрын
I couldn't come up with this solution. Is there a particular name to this sort of algorithm (eg: 2-pointer)? If so that's a new concept and I'd like to explore similar questions. If not, that's a definitely creative solution. How did you come up with this? Does it just come with practice? Is it possible to learn this power :O?
@satyajeetjha1681
@satyajeetjha1681 4 жыл бұрын
You need to solve problems to be able to solve problems and you need to think hard. It is hard to come up with solutions and it comes with practice. If you do a simple level order traversal of bst, you can easily do right side view of bst as well. So it comes with thinking and time. I assume you aren't God gifted.
@divyanshdixit4944
@divyanshdixit4944 3 жыл бұрын
Read about monotonic stacks
@vinaygupta2369
@vinaygupta2369 2 жыл бұрын
O(N) solution is java - public static int[] dailyTemperatures(int[] temperatures) { int length = temperatures.length; int[] output = new int[length]; Stack stack = new Stack(); // use stack for filling the output array for(int i = length-1;i>=0;i--) { while(!stack.isEmpty() && temperatures[i]>=temperatures[stack.peek()]) { stack.pop(); } // If the stack still has elements, then the next warmer temperature exists! if(!stack.isEmpty()) { output[i] = stack.peek() - i; } // Inserting current index in the stack: monotonicity is maintained! stack.push(i); } return output; }
@kseniaeugene7177
@kseniaeugene7177 4 жыл бұрын
Why do you need a tuple? you can put only the indices on Stack and then look up the actual value by calling T[stack.peek()]
@nikunjgupta2107
@nikunjgupta2107 4 жыл бұрын
Are you God?
Leetcode Visualized: 647. Palindromic Substrings
18:07
Alexander Le
Рет қаралды 18 М.
Leetcode Visualized: 581. Shortest Unsorted Continuous Subarray
13:47
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 1,9 МЛН
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 15 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 166 МЛН
Daily Temperatures - Leetcode 739 - Stacks (Python)
12:35
Greg Hogg
Рет қаралды 7 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 116 М.
LEETCODE 146 (JAVASCRIPT) | LRU CACHE
17:42
Andy Gala
Рет қаралды 4,7 М.
Beginner React.js Coding Interview (ft. Clément Mihailescu)
36:31
Ben Awad
Рет қаралды 2,2 МЛН
Sports day paavangal | Parithabangal
15:58
Parithabangal
Рет қаралды 2,8 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 852 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
37C3 -  Breaking "DRM" in Polish trains
1:01:46
media.ccc.de
Рет қаралды 446 М.
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 1,9 МЛН