How to EASILY solve LeetCode problems

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

Комментарии • 93

  • @utkarshdewan8736
    @utkarshdewan8736 6 месяцев назад +595

    This umm.. went over my head tbh. Although good for a quick revision for those who have already solved this or aware about the concept or the trick

    • @NeetCode
      @NeetCode  6 месяцев назад +77

      Yeah, YT has a time limit of 60 seconds which makes this tough. I post the same shorts on Instagram, which has a time limit of 90 seconds, they are usually easier to follow.
      This is my Instagram if anyone wants to follow: instagram.com/neetcodeio

    • @darshanvanza3889
      @darshanvanza3889 6 месяцев назад +1

      @@NeetCode without any doubt, followed ✌️

    • @jayrigger7508
      @jayrigger7508 6 месяцев назад +2

      My issue is the graph .. I can't see the speed correlation on it .

    • @D0CTOR-ZED
      @D0CTOR-ZED 6 месяцев назад

      ​@jayrigger7508 The speed is the slope. As far as solving it, you can calculate when they would reach the destination if there wasn't any other cars (distance/speed), then from front to back track keep a running max time and each time you increase it, it is a new fleet. The logic behind that is if a car would get there quicker than cars ahead of it, it becomes part of a fleet, if they arrive after all cars ahead, they are a new fleet.

    • @somerandomboi8239
      @somerandomboi8239 5 месяцев назад

      ​@@jayrigger7508the way I see the problem is that 5 catches up to 8 and 0 to 3, and that's two lines, and 10 is the 3rd. I don't get his graph at all

  • @fogcat5
    @fogcat5 6 месяцев назад +740

    the second rule of leetcode is to figure out where to use a hashmap ;)

    • @Aashishbedi0
      @Aashishbedi0 6 месяцев назад +18

      Underrated but best

    • @shishirarora8808
      @shishirarora8808 6 месяцев назад +25

      for remaining ones use recursion tree

    • @feliche-demiannetliukh3703
      @feliche-demiannetliukh3703 5 месяцев назад +10

      What means where? I firstly solve the problem with hashmap and then start think😂

    • @prakashgode8232
      @prakashgode8232 4 месяца назад

      @@feliche-demiannetliukh3703 lol

    • @daniellige5311
      @daniellige5311 4 месяца назад +1

      This problem doesn't require a hashmap, it's using monotonic stack.

  • @AlwafiCharki
    @AlwafiCharki 3 месяца назад +124

    Bro i didnt even understand the problem 😂

    • @sonyolcu23
      @sonyolcu23 2 месяца назад +17

      Number 0 rule of leetcode problem, understand and explain it to your followers.

  • @rami9274
    @rami9274 20 дней назад +7

    The coding problems on sites like leetcode are always worded so strangely

  • @lvmrjb
    @lvmrjb 6 месяцев назад +116

    It sucks because this is what whiteboarding interviews were for, literally visually solve the problem first with the interviewer -> code it out. Now with all virtual interviews, it’s much harder to communicate if you can’t verbalize exactly how you’re problem solving/thinking

    • @dhruva1221
      @dhruva1221 6 месяцев назад +17

      Yeah
      My exp recently has been that intvwr dont wanna look how i find pattern or figure out a part of solution working in 30min but i just have to code 100% perfect most optimized solution

  • @venkatinator
    @venkatinator 6 месяцев назад +43

    Thanks! Do you really need a stack? What about O(1) space just by scanning right to left. Compute arrival time of element R then scan leftwards with L pointer to skip all elements with earlier arrival times. Then increment your count. Snap the R pointer to L pointer. And repeat.

  • @DaThuFlorida
    @DaThuFlorida 6 месяцев назад +12

    Bro, you are one of the rare programming lecturers on RUclips that visualize the problems 😭

  • @lingyundai964
    @lingyundai964 6 месяцев назад +14

    i remember learning this problem it was such a brilliant solution

  • @WazobiaTechGuy
    @WazobiaTechGuy 6 месяцев назад +32

    How am i supposed to come up with that graph though

    • @AniketSingh-hr8mi
      @AniketSingh-hr8mi 3 месяца назад +20

      10% luck
      20% skill
      15% concentrated power of will
      5% pleasure
      50% pain, and
      100% reason to remember the name

    • @playfulcyanide
      @playfulcyanide 3 месяца назад

      Math

  • @sergeynazarov2473
    @sergeynazarov2473 6 месяцев назад +10

    So naive recomendation, the most difficult part of LC problems solving is to understand what is needed.

  • @TheRealFak3rRLive
    @TheRealFak3rRLive 6 месяцев назад +5

    Yeah I do that too, but my problem is just turning my answer to code is hard..
    lol I guess that only be fixed with time

  • @lxchurbakov
    @lxchurbakov 6 месяцев назад +1

    Awesome explanation

  • @killerthoughts6150
    @killerthoughts6150 6 месяцев назад +5

    LoL my brain was screaming union find union find!! Lol

  • @unebonnevie
    @unebonnevie 6 месяцев назад +2

    Computer science interviews have gone rogue!

  • @KingXKok
    @KingXKok 6 месяцев назад +1

    Why do you need to do the [list comprehension] instead of just calling sorted on the zip output?

  • @Supakills101
    @Supakills101 6 месяцев назад

    Lowkey buying a drawing tablet levelled up my leetcode game 🎉

  • @ahmedelhadary1899
    @ahmedelhadary1899 6 месяцев назад

    thanks for that great video, I have one question which is should I solve leetcode problems after finishing each topic (I mean solving problems on each specific topic) or should I wait until I finish the full DSA roadmap of whatever course I'm taking then start solving problems on the full DSA?

  • @dera_ng
    @dera_ng 6 месяцев назад

    Beautiful ❤️

  • @Supercell_2003
    @Supercell_2003 4 месяца назад

    The array speed is enough to solve this problem just by comparing the speeds of those cars.

  • @MehdiGlz
    @MehdiGlz 6 месяцев назад +15

    Fucking python man, I swear it already solves all the DS parts of any leetcode problem

    • @ChinaNumbaOne1
      @ChinaNumbaOne1 4 месяца назад +11

      Don’t think you understand what leet code is about

    • @arnv4487
      @arnv4487 3 месяца назад +2

      Do you think leetcode is about implementing a stack? Lmao

  • @XIInfernoIX_
    @XIInfernoIX_ 4 месяца назад

    I don’t even know data structures or algo bc imma go to college this year and that seems hard

  • @krishna9virgo
    @krishna9virgo Месяц назад

    Why cant u use a small math problem which is DST to solve this .. by calculating the displacement from the target and we know the speed. So we would know which can reach first

  • @Max-ju6be
    @Max-ju6be 2 месяца назад

    Thats so easy to visualize. I could have told you 3 and Im a mechanical engineer.

  • @maxwellkendall8391
    @maxwellkendall8391 4 месяца назад

    What is the drawing tool you use?

  • @RolopIsHere
    @RolopIsHere 5 месяцев назад +1

    At least leetcode gives you drawings, during the interview they wont give you any diagram or drawing so understanding the problem is harder.

  • @yashhashy
    @yashhashy Месяц назад

    what if sometimes we know how canit be done at least with brute BUT dont know how to code it or write ?????

  • @user-iqplayer
    @user-iqplayer 5 месяцев назад +12

    just a math problem💀💀💀

  • @Midlifecrypto
    @Midlifecrypto 2 месяца назад

    The math he's referring to is simply the formula:
    time = distance / speed

  • @shravankumarv2524
    @shravankumarv2524 4 месяца назад +1

    This sounds good. But, in interviews online where we have to work on Google document, it’s not possible to do the visuals easily. Is there a solution to bring whiteboard experience of free hand writing in interviews with FAANG companies?

    • @harryzhu
      @harryzhu 2 месяца назад

      google docs u can go to insert and then click drawing.. yw!

    • @shravankumarv2524
      @shravankumarv2524 2 месяца назад

      @@harryzhu Thanks. I opened this tool, but the default is still predefined shape templates. Under line, free scribbling line option is available. I guess it takes some practice to master it so that we can use them effectively in the interviews

  • @TheDoooot
    @TheDoooot 2 месяца назад

    Thanks now I know how many car fleets will reach 12 😮

  • @ZYLYTYourCrazyAbility
    @ZYLYTYourCrazyAbility 6 дней назад

    What would be your #1 rule to approach a ZYLYTY code challenge?

  • @natureshorts9201
    @natureshorts9201 4 месяца назад

    Lol, that’s my question that I ask in interviews haha😂

    • @LaughingMan44
      @LaughingMan44 2 месяца назад

      For web dev roles right? Definitely needed and useful

  • @maharudar723
    @maharudar723 4 месяца назад

    Please add subtitles to your videos. It will help learn the subtitle readers like me.

  • @baner3744
    @baner3744 6 месяцев назад

    With all this wisdom, google can’t give you decent search results results 😢

  • @zacurrya9485
    @zacurrya9485 2 месяца назад

    Differentiation?

  • @johnconnor9787
    @johnconnor9787 6 месяцев назад

    On the femonsttation cars go from left to right... But finish line is on top ))) Still not clear))

  • @maxguichard4337
    @maxguichard4337 5 месяцев назад +12

    One liner for all of y'all trying to fail your job interview 🙌
    reduce(lambda fla, pair: (fla[0] + int((target - pair[0]) / pair[1] > fla[1]), max(fla[1], (target - pair[0]) / pair[1])), sorted(zip(position, speed), reverse=True), (0, -1))[0]

    • @LaughingMan44
      @LaughingMan44 2 месяца назад

      That's the ugliest code I've ever seen.

    • @FestusDevelops
      @FestusDevelops 2 месяца назад

      That got me 😂😂😂

  • @jatinpathak8861
    @jatinpathak8861 6 месяцев назад +4

    I'm f'd up .

  • @LaughingMan44
    @LaughingMan44 2 месяца назад

    I dont get who would need to know this outside of high level engineers, machine learning, etc

  • @srinathpl6142
    @srinathpl6142 6 месяцев назад +1

    Can you tell the problem name?

    • @NeetCode
      @NeetCode  6 месяцев назад +5

      Car Fleet

    • @srinathpl6142
      @srinathpl6142 6 месяцев назад +1

      @@NeetCode thank you bro 👍

  • @dongwalker6234
    @dongwalker6234 2 месяца назад

    high school math problem😂

  • @shubheshswain5480
    @shubheshswain5480 3 месяца назад +1

    Time to get back to farming

  • @abajaj1510
    @abajaj1510 3 месяца назад

    O1 will solve it for me

  • @waqarqasim216
    @waqarqasim216 3 месяца назад

    You made it more complicated dude

  • @pastori2672
    @pastori2672 6 месяцев назад

    new shirt ?

  • @fevicoI
    @fevicoI 3 месяца назад +4

    Bro wants you to visualise in the middle of the interview of 40 mins 😂

  • @timowendner413
    @timowendner413 6 месяцев назад +1

    1. The first list comprehension is useless ('zip(position, speed)' is sufficient) you just unpack and repack...
    2. the stack is also not needed, you can reverse loop through the array, store the last element and add to a counter if the last time is less than the current time.
    3. you gave a very good intuition, thank you!

  • @raghupusapati515
    @raghupusapati515 3 месяца назад

    Ted Mosby?

  • @beboba2498
    @beboba2498 6 месяцев назад

    number #1 rule is to use chatgpt

  • @ZettaiKatsu2013
    @ZettaiKatsu2013 4 месяца назад

    just forget about this leetcode geek stuff. Real life is different

  • @TheOuchee
    @TheOuchee 3 месяца назад

    >Now it's just a math problem
    Umm.........I don't think that makes it easier my good sir (good advice though, I'm just making a joke)

  • @BishuBaswal
    @BishuBaswal 2 месяца назад

    wow

  • @andrefreitas9936
    @andrefreitas9936 4 месяца назад

    that is linear programming

  • @ladenNugg
    @ladenNugg 2 месяца назад

    Ok

  • @dafivers4127
    @dafivers4127 3 месяца назад

    You need better lighting bro bro

  • @Smoshylife
    @Smoshylife 4 месяца назад

    I never get this question cause it’s to make no sense

  • @LAFLAME1111
    @LAFLAME1111 6 месяцев назад

    Oh man, imma need a full video on this. I got lost

    • @NeetCode
      @NeetCode  6 месяцев назад +1

      i got you chief: ruclips.net/video/Pr6T-3yB9RM/видео.html

    • @jayrigger7508
      @jayrigger7508 6 месяцев назад

      ​@@NeetCodenon-clickable or copyable link 😢

  • @Tmahmoud5811
    @Tmahmoud5811 5 месяцев назад

    😂😂

  • @duarteribeiro1520
    @duarteribeiro1520 Месяц назад

    Bro you barely explained the problem

  • @oglothenerd
    @oglothenerd 6 месяцев назад +2

    LeetCode is kind of a joke.