Coding Interview Problem - Car Fleet
14:39
Пікірлер
@Mrflippy4
@Mrflippy4 28 күн бұрын
Great great great! 👏
@MedhatR-do9le
@MedhatR-do9le Ай бұрын
great explantation thanks
@sanshubhkukutla4043
@sanshubhkukutla4043 2 ай бұрын
Great explanation thanks!
@pranavkumar1818
@pranavkumar1818 2 ай бұрын
Nice explanation man !
@Martinnnnnn-e5s
@Martinnnnnn-e5s 3 ай бұрын
After watching like 5 videos about this question finally there's one that i understand. amazing explantion
@Alex-tm5hr
@Alex-tm5hr 3 ай бұрын
Just a heads up - this is for LC Combination Sum IV.
@drewlee7435
@drewlee7435 4 ай бұрын
literally THE best explanation i've seen
@janpoonthong
@janpoonthong 5 ай бұрын
Great video
@AnarchySane
@AnarchySane 7 ай бұрын
Great. Thank you very much❤
@ivandrofly
@ivandrofly 7 ай бұрын
Thanks
@manwinsingh7381
@manwinsingh7381 9 ай бұрын
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.
@velakuruday
@velakuruday 9 ай бұрын
Thank you brother. Only you explained why the i-1 + i-2 is valid.
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you
@subee128
@subee128 9 ай бұрын
Thank you
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you
@subee128
@subee128 9 ай бұрын
Thank you
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thank you very much
@subee128
@subee128 9 ай бұрын
Thanks
@shahzadsaleem8142
@shahzadsaleem8142 10 ай бұрын
Perfect explanation of recursion
@subee128
@subee128 10 ай бұрын
Thanks
@subee128
@subee128 10 ай бұрын
Thanks
@subee128
@subee128 10 ай бұрын
Thanks
@noble.things
@noble.things 10 ай бұрын
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….
@AnkurTeotia9600
@AnkurTeotia9600 11 ай бұрын
this is the most inituitive solution out of all solutions present for this problem imo.
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 11 ай бұрын
so good, thank you :)
@gradientO
@gradientO Жыл бұрын
best explanation for this question!
@AlvaroGarcia-fb6oh
@AlvaroGarcia-fb6oh Жыл бұрын
First video that helped me understand the tabulation solution! Thanks a lot man.
@hashtagcc
@hashtagcc Жыл бұрын
Ur videos are awesome pls post more videos
@floatingpoint7629
@floatingpoint7629 Жыл бұрын
you should also do a dry run of the code on sample input. just looking at code does not help understand
@prakhyat2001
@prakhyat2001 Жыл бұрын
thanks a lot
@VivekSingh99
@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
@light7958 Жыл бұрын
thanks! easy to understand
@EMAWgasm
@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
@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
@chemistryman6053 Жыл бұрын
please increase the font size
@KnapsackLabs
@KnapsackLabs Жыл бұрын
Done in future videos! Thanks for the feedback.
@bluesteel1
@bluesteel1 Жыл бұрын
Nice video
@mohammedabulsoud1819
@mohammedabulsoud1819 Жыл бұрын
Thanks!
@parthpatel4980
@parthpatel4980 Жыл бұрын
ur the goat! u saved my life
@marspark6351
@marspark6351 Жыл бұрын
The sound is not synced with the video starting from 6:33. Would be nice if you can correct it
@PremPal-uy4nm
@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
@PremPal-uy4nm Жыл бұрын
Thank You! Thank You! Thank You! I can finally die in peace.
@neo9530
@neo9530 Жыл бұрын
Thank you! Finally I can die in peace.
@SS-cz3vg
@SS-cz3vg Жыл бұрын
Amazing explanation and so easy to understand.