LeetCode Odd Even Jump Solution Explained - Java

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
    Join my free exclusive community built to empower programmers! - www.skool.com/...
    Preparing For Your Coding Interviews? Use These Resources
    --------------------
    (My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.d...
    AlgoCademy - algocademy.com...
    Daily Coding Interview Questions - bit.ly/3xw1Sqz
    10% Off Of The Best Web Hosting! - hostinger.com/...
    Follow Me on X/Twitter - x.com/nickwhit...
    Follow My Instagram - / nickwwhite
    Other Social Media
    ----------------------------------------------
    Discord - / discord
    Twitch - / nickwhitettv
    TikTok - / nickwhitetiktok
    LinkedIn - / nicholas-w-white
    Show Support
    ------------------------------------------------------------------------------
    Patreon - / nick_white
    PayPal - paypal.me/nick....
    Become A Member - / @nickwhite
    #coding #programming #softwareengineering

Komentáře • 44

  • @MrNetsecure
    @MrNetsecure Před 4 lety +26

    How in the name of god can anyone solve this question in a 45 minute interview, if they hanvet already done this question before.

    • @shivampurbia6169
      @shivampurbia6169 Před 4 lety

      lol, i agree man

    • @greyreynyn
      @greyreynyn Před 3 lety +5

      yeah 30 mins in i was like “what the fuck am i doing with my life this is so pointless lol”

    • @arnabpersonal6729
      @arnabpersonal6729 Před 3 lety

      we can atleast we can come up with a o(n^2) solution in that time

    • @LegitGamer2345
      @LegitGamer2345 Před 3 lety

      well you are supposed to solve it beforehand if ur not a genius

    • @kumarvansh007
      @kumarvansh007 Před 2 měsíci

      thats the point , someone told me if an interviewer gave u to solve dp ques then he/she hates u already🤣

  • @ShaliniNegi24
    @ShaliniNegi24 Před 3 lety +6

    The description of the problem given in leetcode is really bad, once you understand the problem it's not difficult to formulate and code.

  • @jugsma6676
    @jugsma6676 Před 4 lety +5

    For Pythonic candidates, don't worry about not having TreeMap, I've build minimal version that fit's for this solution,
    import sys
    def get_higher(entry, val):
    min_val = sys.maxsize
    for k, v in entry.items():
    if k >= val:
    if k-val

  • @DEEPAKGOYALnullRA
    @DEEPAKGOYALnullRA Před 4 lety +9

    i think you need to explain it on white board
    its difficult to understand large problem with expression only.

  • @sameer1571
    @sameer1571 Před 3 lety +1

    Can anyone tell me why our answer is getting only updated in the case of higher[i] is true and not in the case of lower[i]

    • @gilshapir7935
      @gilshapir7935 Před 3 lety

      Because you always start with an odd transaction (start with an even transaction does not count, per the question rules).

  • @sameer9368
    @sameer9368 Před 5 lety +3

    great explanation...keep it up. you really explain the solution very well. Love from India.

  • @biswaMastAadmi
    @biswaMastAadmi Před 7 měsíci +1

    Good job Nick !

  • @dincerbeken5761
    @dincerbeken5761 Před 2 lety +1

    Really great explanation of wtf dynamic programming is.

  • @satang500
    @satang500 Před 5 lety +1

    how come index 0 is being treated as odd index? Don't we treat 0 as even number?
    if i is odd index, then find larger values and then choose smallest among them
    if i is even index, then find smaller values and then choose largest among them
    for index 0, this finds larger values (which are 13, 12, 14, 15) and then find min (13, 12, 14, 15) = 12
    so i'm confused, since index 0 is treated as odd index.

    • @eddieguardado5002
      @eddieguardado5002 Před 4 lety +1

      The index means nothing really. It is just where you are starting. You are counting the jumps you make(i.e. The first jump from index i is odd and the 2nd is even and so forth). I had the same issue understanding the question as well.

    • @hugaomarques
      @hugaomarques Před 4 lety +2

      It's not about the index but about the number of jumps. For example, if you start at 14 to arrive at 15 you are on your 1st jump so you treat as an odd jump. However, if you arrive at 14 due to another jump 14 forward will be your 2nd jump which is an even jump. It took me a while to realize this as well.

  • @ranjithsubramaniam5930

    We can use ceilingKey and floorKey instead of ceilingEntry and floorEntry

  • @theEpicFailSquad123
    @theEpicFailSquad123 Před 2 lety

    Why use a treemap here? Can we not just store the smallest number, index and largest number,index above the current index? At 12 this would be 14,3 and 15,4. This would give us the next jumps for even and odd jumps at every index going backwards. Does that make sense?

  • @VishalGupta92
    @VishalGupta92 Před 2 lety

    why did leetcode removed the editorial solution from site ?

  • @GauravKulkarniDombivli
    @GauravKulkarniDombivli Před 4 lety +2

    Great explanation!! Keep it up!! Your videos are amazing.. I have one question though. Wouldn't ceilingEntry(A[i]) would always return index of 15 in this case? Or in general case when higher number is actually somewhere in between, it would return index of that number right? Then why not get the index of it in the beginning by sorting array (best is log(N) ) and then pass that value in comparisons?

    • @nigamsn748
      @nigamsn748 Před 2 lety +1

      Notice that we are moving from right to left. So any element before the current element is not inserted into treeMap yet. So it wont be looking backwards

  • @rutvizvyas5007
    @rutvizvyas5007 Před 4 lety

    Great explanation... It really helped me in understanding the question and the approach..

  • @nikhilchandna4851
    @nikhilchandna4851 Před 3 lety +1

    Great Explanation
    You make it so easy

  • @wentingsong9435
    @wentingsong9435 Před 2 lety

    Thank you for saving me so much time to figure it out on my own

  • @ocoocososococosooooosoococoso

    amazing, bro. You explained well, preparing for the upcoming google interview

  • @ayushsingh1315
    @ayushsingh1315 Před 4 lety

    That was the best explanation. PERIOD.

  • @hovering_developer
    @hovering_developer Před rokem

    I really liked you explained the solution. However, in the interviews, if i directly jump into the solution, it will be evident that I knew the solution and hence that'll impact negatively. It'll be great if you could've explained how the solution can be evolved from a brute force solution. Thanks again for explaining DP solution.

  • @lifehacks9450
    @lifehacks9450 Před 4 lety

    really amazing pls uplod more dynamic programing problem

  • @neeruksingh
    @neeruksingh Před rokem

    great ques explanation !!!

  • @lifehacks9450
    @lifehacks9450 Před 4 lety

    wonderfull explaination believe me u r doing a great job

  • @AmolGautam
    @AmolGautam Před 2 lety

    Thank you for the explaination.

  • @TheKebTsegayePodcast
    @TheKebTsegayePodcast Před 3 lety

    Really appreciate this video.

  • @1mevolution219
    @1mevolution219 Před 3 lety

    Can someone help understand the real life application of this problem?

  • @vinaypatil7879
    @vinaypatil7879 Před 2 lety

    thanks great explanation.

  • @LegitGamer2345
    @LegitGamer2345 Před 3 lety

    great explanation

  • @manmohangupta5449
    @manmohangupta5449 Před 2 lety

    thnaks a lot bro! :)

  • @kratigupta80
    @kratigupta80 Před 3 lety

    You are a saviour !

  • @californiaflying6637
    @californiaflying6637 Před rokem

    Great, now figure it out in 30 minutes of interview time LOL

  • @Habzz52
    @Habzz52 Před 2 lety +1

    Thank you so much, your explanation was great and you made it very easy to follow! As for the problem itself, I think it was invented by Satan himself

  • @lokesh-qz6cc
    @lokesh-qz6cc Před 3 lety

    clap

  • @RagazzoKZ
    @RagazzoKZ Před 4 lety +4

    This problem is a crap