Number of Dice Rolls with Target Sum - Leetcode 1155 - Python

Поділитися
Вставка
  • Опубліковано 18 вер 2024

КОМЕНТАРІ • 36

  • @massimomonticelli6010
    @massimomonticelli6010 8 місяців тому +10

    A small improvement for the first solution (memoization) is to include a base case that stops recursion if the target becomes negative.

  • @YashRekha594
    @YashRekha594 8 місяців тому +12

    I'm done for today. New year resolution would be to learn dynamic programming 😅

  • @MP-ny3ep
    @MP-ny3ep 8 місяців тому +3

    Merry Christmas Neetcode !

  • @jayberry6557
    @jayberry6557 8 місяців тому +6

    Giving 5 easies in row just to hit u with DP problem on Christmas day 😂😂 Someone had a bad day

    • @KnightMirkoYo
      @KnightMirkoYo 8 місяців тому +1

      Well, problems through the entire December until 25th were really easy (even those marked as medium), and then they hit us with 2 DP in a row 😅

  • @harshithdesai9989
    @harshithdesai9989 8 місяців тому +7

    Hello people. I have a hard time visualizing the backtracking tree and providing the Dynamic Programming optimization for it. Can anyone help me to get better at this and also to get better at solving DP problems....
    🙂

  • @dimplepandya9522
    @dimplepandya9522 8 місяців тому +2

    merry Christmas!

  • @satwiktatikonda764
    @satwiktatikonda764 8 місяців тому +6

    wonderful solution but if you go memoization ->tabulation ->tabulation(space optimized) it
    would be helpful for beginners to learn all 3 variations

    • @two697
      @two697 8 місяців тому

      Thf he's done a bunch of problems almost identical to this where he's done it in that order. There's no need to go through it again every time.

    • @satwiktatikonda764
      @satwiktatikonda764 8 місяців тому

      @@two697 you may be skilled enough and you may dnt need it
      I am talking from a beginner perspective

    • @NeetCodeIO
      @NeetCodeIO  8 місяців тому +13

      The main reason I don't always do this is because it results in a very long video, which most people won't watch.

    • @omarr993
      @omarr993 8 місяців тому

      most people won't watch and also most companies wouldn't even expect you to come up with tabulation(space optimized) method during an interview, only small % of people would probably be capable of doing that on the spot and they usually go through other resources to learn that niche stuff

    • @coolgamertm4411
      @coolgamertm4411 8 місяців тому

      @@NeetCodeIO true i would say

  • @rdwok14
    @rdwok14 8 місяців тому +1

    Merry Christmas!

  • @m.kamalali
    @m.kamalali 8 місяців тому

    hey neetcode , i think we can rid off next_dp array if we build the solution up-bottom
    mod=10**9+7
    dp=[0]*target+[1]
    for i in range(n-1,-1,-1):
    for s in range(target+1):
    dp[s]=0
    for j in range(1,k+1):
    if s+j>target:break
    dp[s]=(dp[s]+dp[s+j])%mod
    return dp[0]

  • @lavanyam3224
    @lavanyam3224 5 місяців тому

    The thumbnails of your previous videos were better with Company logos.. please continue putting company logos in the thumbnail as it is easy to pick company specific questions xD

  • @onlinealias622
    @onlinealias622 8 місяців тому

    I got the memoization solution myself but the bottom up tabulation solutions are tricky :/

  • @boehan605
    @boehan605 8 місяців тому +1

    i wish i was as good as you 😭

  • @kostiantynivanov6875
    @kostiantynivanov6875 8 місяців тому +1

    Is that a medium complexity problem for real? You need to be a real smart ass to figure that out.
    As for me, it's not about programming in general - it's more about having uni education to be able to build such math yourself.
    I'm also curious how much time did it take for you to solve this problem?

  • @gmbabar
    @gmbabar 8 місяців тому

    Why we take mod as 10**9 + 7?

    • @caiodavi9829
      @caiodavi9829 8 місяців тому

      because its a prime number

  • @ruzibayevich1693
    @ruzibayevich1693 8 місяців тому

    why don't you publish the solution on leetcode ?

  • @prashanthkurella4500
    @prashanthkurella4500 8 місяців тому +1

    Why do we need the mod

    • @bundiderp5109
      @bundiderp5109 8 місяців тому +2

      To not overflow the number we are tracking.

  • @ChrisBakare
    @ChrisBakare 8 місяців тому +1

    Another problem down the drain for me. I barely understood your solution (not your fault). I need to study DP and backtracking. You would think a degree would prepare you for that.

    • @ej6431
      @ej6431 8 місяців тому +1

      same boat, don't stress too much we got this

    • @coolkaw4497
      @coolkaw4497 8 місяців тому +2

      I was completely lost with DP until I watched videos such as Tech with Nikola and his Mastering Dynamic Programming videos. In addition, I would suggest doing easier DP problems as well such as House Robber. While I couldn’t come up with a solution for this problem, I can at least understand the solutions! Good luck, let’s all work for a better future

    • @ej6431
      @ej6431 8 місяців тому

      thank you sir@@coolkaw4497

  • @prakhar4585
    @prakhar4585 8 місяців тому +2

    I think I am too young for this concept 😅🤣

    • @coolkaw4497
      @coolkaw4497 8 місяців тому +1

      Never too young to learn programming ! Be ahead of the game !

  • @Bfhehdhhx
    @Bfhehdhhx 8 місяців тому +1

    merry Christmas!

  • @YansongLi
    @YansongLi 8 місяців тому

    Merry Christmas!