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

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
    🥷 Discord: / discord
    🐦 Twitter: / neetcode1
    🐮 Support the channel: / neetcode
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
    Problem Link: leetcode.com/problems/number-...
    0:00 - Read the problem
    0:30 - Explaining Memoization solution
    6:14 - Coding Memoization solution
    10:01 - Explaining DP solution
    15:17 - Coding DP solution
    leetcode 1155
    #neetcode #leetcode #python

Komentáře • 36

  • @massimomonticelli6010
    @massimomonticelli6010 Před 6 měsíci +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 Před 6 měsíci +12

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

  • @jayberry6557
    @jayberry6557 Před 6 měsíci +6

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

    • @KnightMirkoYo
      @KnightMirkoYo Před 6 měsíci +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 😅

  • @MP-ny3ep
    @MP-ny3ep Před 6 měsíci +3

    Merry Christmas Neetcode !

  • @dimplepandya9522
    @dimplepandya9522 Před 6 měsíci +2

    merry Christmas!

  • @RSWDev
    @RSWDev Před 6 měsíci +1

    Merry Christmas!

  • @harshithdesai9989
    @harshithdesai9989 Před 6 měsíci +6

    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....
    🙂

  • @m.kamalali
    @m.kamalali Před 6 měsíci

    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]

  • @boehan605
    @boehan605 Před 6 měsíci +1

    i wish i was as good as you 😭

  • @onlinealias622
    @onlinealias622 Před 6 měsíci

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

  • @satwiktatikonda764
    @satwiktatikonda764 Před 6 měsíci +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 Před 6 měsíci

      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 Před 6 měsíci

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

    • @NeetCodeIO
      @NeetCodeIO  Před 6 měsíci +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 Před 6 měsíci

      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 Před 6 měsíci

      @@NeetCodeIO true i would say

  • @lavanyam3224
    @lavanyam3224 Před 3 měsíci

    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

  • @kostiantynivanov6875
    @kostiantynivanov6875 Před 6 měsíci +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?

  • @ruzibayevich1693
    @ruzibayevich1693 Před 6 měsíci

    why don't you publish the solution on leetcode ?

  • @gmbabar
    @gmbabar Před 6 měsíci

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

  • @prashanthkurella4500
    @prashanthkurella4500 Před 6 měsíci +1

    Why do we need the mod

    • @bundiderp5109
      @bundiderp5109 Před 6 měsíci +2

      To not overflow the number we are tracking.

  • @ChrisBakare
    @ChrisBakare Před 6 měsíci +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 Před 6 měsíci +1

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

    • @coolkaw4497
      @coolkaw4497 Před 6 měsíci +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 Před 6 měsíci

      thank you sir@@coolkaw4497

  • @prakhar4585
    @prakhar4585 Před 6 měsíci +1

    I think I am too young for this concept 😅🤣

    • @coolkaw4497
      @coolkaw4497 Před 6 měsíci +1

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

  • @Bfhehdhhx
    @Bfhehdhhx Před 6 měsíci +1

    merry Christmas!

  • @YansongLi
    @YansongLi Před 6 měsíci

    Merry Christmas!