After watching like 5 videos about this question finally there's one that i understand. amazing explantion
@Alex-tm5hr3 ай бұрын
Just a heads up - this is for LC Combination Sum IV.
@drewlee74354 ай бұрын
literally THE best explanation i've seen
@janpoonthong5 ай бұрын
Great video
@AnarchySane7 ай бұрын
Great. Thank you very much❤
@ivandrofly7 ай бұрын
Thanks
@manwinsingh73819 ай бұрын
Bro. You made my day. I was exhausted by this problem and couldn't find a correct explanation. Your dry runs and explanation were way too smooth. Thank you so much.
@velakuruday9 ай бұрын
Thank you brother. Only you explained why the i-1 + i-2 is valid.
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you
@subee1289 ай бұрын
Thank you
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you
@subee1289 ай бұрын
Thank you
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thank you very much
@subee1289 ай бұрын
Thanks
@shahzadsaleem814210 ай бұрын
Perfect explanation of recursion
@subee12810 ай бұрын
Thanks
@subee12810 ай бұрын
Thanks
@subee12810 ай бұрын
Thanks
@noble.things10 ай бұрын
Thanks so much for the excellent explanation of the problem. It really crystallized it for me. That being said, it seems there might be a bug in the code though. In the case where there are no collisions (i.e. no car catches up to another car), the resulting fleet count should be the total number of cars (since each individual car is a fleet), but based on this code, it will be 1. Disclaimer: I didn't actually run the code, but just from looking at it, "fleet_count" is initialized to zero and incremented only when there's a collision, and once again after exiting the "for" loop. Unless I’m missing something….
@AnkurTeotia960011 ай бұрын
this is the most inituitive solution out of all solutions present for this problem imo.
@a_maxed_out_handle_of_30_chars11 ай бұрын
so good, thank you :)
@gradientO Жыл бұрын
best explanation for this question!
@AlvaroGarcia-fb6oh Жыл бұрын
First video that helped me understand the tabulation solution! Thanks a lot man.
@hashtagcc Жыл бұрын
Ur videos are awesome pls post more videos
@floatingpoint7629 Жыл бұрын
you should also do a dry run of the code on sample input. just looking at code does not help understand
@prakhyat2001 Жыл бұрын
thanks a lot
@VivekSingh99 Жыл бұрын
I have been trying to understand this question for the entire day and I FINALLY GET IT. Thank you this is so well put together.
@light7958 Жыл бұрын
thanks! easy to understand
@EMAWgasm Жыл бұрын
Nice! I didn't think to flip the integers to negative, but when you did that, something else in my brain clicked. If we keep a running sum of the index + (-array[index]), then we know that the lights will all be energized if this sum == 0, so I came up with something like this: int count = 0 int energized = 0 for (int i = 0; i < array.Length; i++) { energized += i + 1; energized += -array[i]; if (energized == 0) count++; } return count; I know this vid is like 2 years old, but thought I'd share in case anyone else stumbles upon this.
@obedpadilla5264 Жыл бұрын
I finally managed to make my own implementation in java with my limited programming knowledge haha import java.util.Arrays; public class CarFleet { public static void main(String[] args) { int carDistance = 12; int[] carPositions = {2, 0, 4, 7}; int[] carSpeeds = {4, 1, 2, 1}; System.out.println(countCarFleets(carDistance, carPositions, carSpeeds)); // expected fleets: 2 } public static int countCarFleets(int distance, int[] position, int[] speed) { int countFleets = 0; int[] carPositions = position.clone(); int[] carSpeeds = new int[speed.length]; Arrays.sort(carPositions); for(int i = 0; i < carSpeeds.length; ++i) { int index = Arrays.binarySearch(carPositions, position[i]); carSpeeds[index] = speed[i]; } int timeFront = (distance - carPositions[carPositions.length - 1]) / carSpeeds[carSpeeds.length - 1]; for(int i = carSpeeds.length - 2; i > -1; --i) { int timeBack = (distance - carPositions[i]) / carSpeeds[i]; if(timeBack > timeFront) { ++countFleets; timeFront = timeBack; } } return ++countFleets; } }
@chemistryman6053 Жыл бұрын
please increase the font size
@KnapsackLabs Жыл бұрын
Done in future videos! Thanks for the feedback.
@bluesteel1 Жыл бұрын
Nice video
@mohammedabulsoud1819 Жыл бұрын
Thanks!
@parthpatel4980 Жыл бұрын
ur the goat! u saved my life
@marspark6351 Жыл бұрын
The sound is not synced with the video starting from 6:33. Would be nice if you can correct it
@PremPal-uy4nm Жыл бұрын
Hey man, I was stuck at LeetCode Gas Station problem from past 3 days. It almost felt like I am doing some kind of research on this problem. Somehow I found your video. I finally understood the optimized solution. Thank you so much. Liked your video and subscribed. Can you tell me how you were able to find solution to that problem? / Did you take any help from books, video or any resource or yourself? What do you recommend, How should someone approach to solve this kind of problem or just understand the solution(optimized solution of gas station)? I am commenting on your latest video, so that I can have your attention. Love you man! From India.
@PremPal-uy4nm Жыл бұрын
Thank You! Thank You! Thank You! I can finally die in peace.