Still a GOATED video, helping thousands of others 4 years later!
@iiimiiim Жыл бұрын
Amazing! Thank you so much for this😍
@pi_nheiro79 ай бұрын
Thank you so much, you explain very well!!
@KushalBhatia4 жыл бұрын
This world need more people like you. Thank you for all the efforts you took to make this video 🙏👍
@powerhead3 жыл бұрын
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()]
@amruthammohan16672 жыл бұрын
Just amazing...❣
@kaitlinzhang137810 ай бұрын
Awesome explanation with great visualizations -- thanks so much for putting this together!
@viridianite2 ай бұрын
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.
@nikhilmishra75723 жыл бұрын
As soon as I saw the stack visual I clicked subscribe button! Great job!
@BS-eu9do2 жыл бұрын
Thanks for great visualisation!
@haifzhan3 жыл бұрын
Good explanation and I like the way you drag the next pointer!
@arpansen4234 жыл бұрын
Thank you, this is the best way to teach algorithms, pl. keep uploading videos regularly
@zhenlinjin31423 жыл бұрын
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 Жыл бұрын
One of the best leetcode explanation videos I have ever seen. Shame you stopped recording them :(
@rahoolification4 жыл бұрын
Keep up the good work my friend. Really appreciate it!!!
@spacesuitred38394 жыл бұрын
Amazing explanation and drawing!
@omarflores42343 жыл бұрын
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!
@xmaxfuture4 жыл бұрын
Thank you so much Alexander
@AmanRaj-gy6qv2 жыл бұрын
Thank you for visualisation, understood the concepts well enough
@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;
@viridianite2 ай бұрын
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.
@SimplyaGameAholic4 жыл бұрын
you deserve a big blue nice like my friend
@saladHz2 ай бұрын
Welp this example really helped just sucked that it began from the end of the list rather than the beginning
@maheiramkhan4 жыл бұрын
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.
@poyanimehta97464 жыл бұрын
Great Explanation Looking for more such videos
@sase10173 жыл бұрын
Great job , but Time and Space analysis?
@shanmukhpatel4 жыл бұрын
Excellent visual presentation! Thank you!
@VenkateshReddyMunagala3 жыл бұрын
Wow! A very with no dislikes and very rightly so. Great Visual demonstration and explanation!
@Abhinavkmr2 жыл бұрын
Thank You!
@snehaashishgupta12543 жыл бұрын
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...
@ahmedouyahya4 жыл бұрын
very beautiful visualization, and clear explanation. Thank you so much.
@alexromero32743 жыл бұрын
This was perfect! Thank you for your visualized videos. They are a huge help for visual learners!! :-)
@knowledge_wings4 жыл бұрын
please make more video ur stuff is wonderful
@chetanshrivastava37624 жыл бұрын
Very nice explanation with visual graphics...
@neelpawar33403 жыл бұрын
This was so good!
@SiddharthMathur2k0073 жыл бұрын
Thank You! :)
@하이-x1i3 жыл бұрын
Finally I can understand!!! thx!!!
@DrSeanKennedy-k2b4 жыл бұрын
Excellent explanation and use of visuals. Where needed I love to use a whiteboard. Subscribed and liked.
@MrDheeraj144 жыл бұрын
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.
@akshdeeprajawat96423 жыл бұрын
Wooooooooooow !
@kc84784 жыл бұрын
very cool
@manojg44514 жыл бұрын
Plzzzzz do more videos ,With this kind of explanation,you will be the to-go channel for leetcode
@paulomarques81474 жыл бұрын
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.
@kaushiktummalapali40004 жыл бұрын
Thanks a ton! Way better explanation than leet code solution break through!
@keller80644 жыл бұрын
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; }
@yeqinghuang21174 жыл бұрын
Thank you. The visualization is super helpful.
@mojo_code4 жыл бұрын
Fantastic job
@metin2dare2 жыл бұрын
ty for sharing
@peddivarunkumar3 жыл бұрын
Thanks!
@yashSharma-pe1dp4 жыл бұрын
sir please upload visualization of other leetcode problems, coz you teaches very well!!
@SeadoooRider4 жыл бұрын
Thanks for the explanation. Great video. Keep doing.
@samriniqbal50964 жыл бұрын
This is so cool.
@tunabozkurt55784 жыл бұрын
Very well done. Thanks.
@chaitanyapatil68393 жыл бұрын
Amazing
@abdallahelkasass63324 жыл бұрын
thank you very very much
@wesammustafa90044 жыл бұрын
Excellent Explanation
@ash2012ash3 жыл бұрын
very well explained. Thanks for making me understand this question.
@Nickel804 жыл бұрын
That was a great explanation. Thank you
@kangniliu79924 жыл бұрын
Subscribed!! Awesome explanation!
@niveenelkhazendar44823 жыл бұрын
Really thanks a lot for your explanation, it halp me very much
@ankitufl4 жыл бұрын
Great explanation
@avneetsng4 жыл бұрын
thanks dude
@sharmilabaskaran73734 жыл бұрын
Thankyou. Please do more leetcode questions
@MangoDrankE4 жыл бұрын
Great explanation. Thank you!
@aliceoioih84713 жыл бұрын
Thank you for sharing! I think it'd be better if without the background music
@Noname-wp6zt4 жыл бұрын
Great explanation!
@kingjohnkk4 жыл бұрын
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 :)
@aleyummusic4 жыл бұрын
What are some other problems similar to this?
@XXXX-ib1vt4 жыл бұрын
Is this the Corpse of Leetcode?
@chankwongyin74552 жыл бұрын
best
@namaratasharma54173 жыл бұрын
Hi, Awsm explanation ..would like to know the tool you are using for visualization
@shivanshsuhane87884 жыл бұрын
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?
@satyajeetjha16814 жыл бұрын
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.
@divyanshdixit49443 жыл бұрын
Read about monotonic stacks
@vinaygupta23692 жыл бұрын
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; }
@kseniaeugene71774 жыл бұрын
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()]