Dynamic Programming lecture #2 - Coin change, double counting

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 189

  • @Errichto
    @Errichto  5 ปีที่แล้ว +159

    Combination sum - leetcode.com/problems/combination-sum-iv/
    Coin change (min) - leetcode.com/problems/coin-change/
    Coin change (count) - leetcode.com/problems/coin-change-2/

    • @yuvrajgarg3921
      @yuvrajgarg3921 5 ปีที่แล้ว

      Hey can you please guide me how I can combine Algorithms with Probability and Statistics.
      I knew Algorithms I knew probability but dint knew how to combine them.

    • @masternobody1896
      @masternobody1896 5 ปีที่แล้ว

      Can you make no bug game or any thing in program...how can we make it possible?

    • @tianyangren
      @tianyangren 4 ปีที่แล้ว +3

      Hi, I am really looking forward to the knapsack problem lecture, which should be the 'mother' problem of many problems:)

    • @siddharthabhi8704
      @siddharthabhi8704 4 ปีที่แล้ว

      csacademy problem Closure -csacademy.com/contest/archive/task/and-closure/ uses forward dp approach

    • @harshmishra7768
      @harshmishra7768 4 ปีที่แล้ว +2

      Hey, what will change if negative numbers are allowed in the array in first question ?

  • @progamerzzz1237
    @progamerzzz1237 3 ปีที่แล้ว +55

    he seems like the most wholesome .Like the people in anime who are not aware how good they are

  • @SuperSam4y0u
    @SuperSam4y0u 4 ปีที่แล้ว +51

    I went over this video 10-12 times for the last 2 days to understand the `why does it work` part rather than `how to solve` and finally I think I understand. Probably nobody else on youtube explains the small details which you do. Thanks for sharing your knowledge Kamil, really appreciate it.

  • @enzodantas4072
    @enzodantas4072 3 ปีที่แล้ว +42

    "Avoid double counting"
    "Avoid double counting"
    I double counted the phrase so I guess I have to rewatch

  • @shivangitomar5557
    @shivangitomar5557 4 ปีที่แล้ว +23

    You are an amazing teacher!!
    I'm finally starting to understand DP

  • @alamintushar5824
    @alamintushar5824 5 ปีที่แล้ว +11

    your videos are so much helpful. please keep up the lectures on DP. liked it very much. Thanks a lot

  • @naughtyrishan
    @naughtyrishan 5 ปีที่แล้ว +5

    Thanks much!! Please do complete all possible questions that you feel would be good in dp and all tricks that would help us in CP down the line!! Great job!! Thanks again @Errichto.

  • @lekdendorji6a
    @lekdendorji6a 5 ปีที่แล้ว +19

    Thank you so much!!! keep making these type of videos

  • @amritbhardwaj99
    @amritbhardwaj99 4 ปีที่แล้ว +1

    One of the best videos on DP ever.!!

  • @RishabhDeepSingh
    @RishabhDeepSingh 5 ปีที่แล้ว +8

    Finally some great DP Series going one

  • @fractal_lynn
    @fractal_lynn 4 ปีที่แล้ว +2

    The coin change problem is what led to me to realize that I needed to learn dynamic programming. Thank you for going over this, your explanations are always crystal clear :D

  • @mridul1161
    @mridul1161 5 ปีที่แล้ว +18

    Hey errichto i am cs student in india inspired by your great approach to problem solving!! looking forward to more in depth video on dp topics !!

  • @Hetp111
    @Hetp111 5 ปีที่แล้ว +97

    Great video! After these DP videos, do videos on graphs please.

    • @shoebmoin10
      @shoebmoin10 5 ปีที่แล้ว +64

      I think he should make a comprehensive DP tutorial series with all the things like bitmask, DP optimizations.

    • @chinmaym7479
      @chinmaym7479 5 ปีที่แล้ว +1

      @@shoebmoin10 Yes

    • @mohammedajaaz8694
      @mohammedajaaz8694 4 ปีที่แล้ว +2

      Erricthto can we have your attention please!

  • @piyushnaithani7689
    @piyushnaithani7689 5 ปีที่แล้ว +6

    Joma Gave this channel a blow.. and I hope Erri will give some interesting content on it, help many aspiring coders...

    • @akramelomrani8728
      @akramelomrani8728 3 ปีที่แล้ว +1

      I can't say no but regardless errichto had + 150k subs before that video so we shouldn't say that he wouldn't succeed without that collab

  • @rahulbhatia1313
    @rahulbhatia1313 5 ปีที่แล้ว +2

    best video ever for learning DP! thanks bro!

  • @chatrughanprasad7778
    @chatrughanprasad7778 4 ปีที่แล้ว

    perfect explanation of coin change and double counting

  • @kishansinha5005
    @kishansinha5005 2 ปีที่แล้ว

    I loved the 'Avoid double counting' joke at the end

  • @kishantiwari3221
    @kishantiwari3221 5 ปีที่แล้ว +1

    You simplify the things so easy. Thank u

  • @lovvyparhar393
    @lovvyparhar393 4 ปีที่แล้ว +1

    Best channel..... Thank You very much..... Keep making videos.

  • @rimurusama5070
    @rimurusama5070 ปีที่แล้ว

    These lectures are gold

  • @svapnilsawant116
    @svapnilsawant116 5 ปีที่แล้ว +8

    Greate! Make a full series of covering different aspects of dp

  • @pranav4592
    @pranav4592 4 ปีที่แล้ว +2

    I love your videos and way you explain. I aspire to be like you at coding!

  • @DHRUVNARAYANSINGH
    @DHRUVNARAYANSINGH 4 ปีที่แล้ว +1

    Great , waiting for tree and graph problem solving series like this.

  • @amangupta-el1gf
    @amangupta-el1gf 5 ปีที่แล้ว +2

    eagerly waiting for 3rd lecture on dp. errichto u r the best.

  • @rajansaharaju1427
    @rajansaharaju1427 5 ปีที่แล้ว +2

    Many many thanks for dp series. Hope you will extend this series.

  • @progamerzzz1237
    @progamerzzz1237 3 ปีที่แล้ว +1

    hey errichto please complete the series by discusiing all the basic problems of dp.Just cover the basic 10 -15 problems

  • @prajwalchoudhary4824
    @prajwalchoudhary4824 5 ปีที่แล้ว +3

    Thank you for all these videos plz make videos on combinatorics,number theory,game theory , geometry etc as these topics aren't covered anywhere

  • @Chakradhar26
    @Chakradhar26 5 ปีที่แล้ว +2

    Errichto we need the next lecture, please!

  • @sarveshdubey9347
    @sarveshdubey9347 5 ปีที่แล้ว +4

    Great video again, thanks a lot

  • @peepforlearning6058
    @peepforlearning6058 4 ปีที่แล้ว +2

    in coin change(min) problem, to overcome negative index use, if(i-x < 0 ) break; inside the for x in nums, before checking the min.

  • @val5_
    @val5_ 5 ปีที่แล้ว +12

    You are literally like a god for me right now

    • @llliiilll3624
      @llliiilll3624 4 ปีที่แล้ว +2

      Calling people god is so cringe.

    • @jayantjha3128
      @jayantjha3128 4 ปีที่แล้ว

      @@llliiilll3624 Nope.

  • @farhan787
    @farhan787 4 ปีที่แล้ว +1

    Kamil what is 'k' at 10:21, is k the largest number in coins array? You said 'k' is the number of them(coins) so is it the size of array and if it's then isn't it k == n (size of coins array)?

  • @jingrenlim1897
    @jingrenlim1897 4 ปีที่แล้ว +1

    This is very helpful.Thank you very much.

  • @himanshusekharsahoo9269
    @himanshusekharsahoo9269 3 ปีที่แล้ว +1

    While solving Combination sum : leetcode.com/problems/combination-sum-iv/
    you might encounter a few issues with overflow
    here is a blog for your help : leetcode.com/problems/combination-sum-iv/discuss/1144739/How-signed-integer-overflow-happened

  • @TheDarkaqua
    @TheDarkaqua 4 ปีที่แล้ว +3

    6:39 the problem with
    ``dp[i] = min(dp[i], dp[i-x]+1)``
    seems that if the coin denomination i.e 'x' is greater than N then it breaks
    eg: nums=[1,10] and N=4
    the array should have 1 coin i*1 times =[0,1,2,3,4] but since we do dp[i-x] i.e dp[1-10] i get an list index out of range error in python.
    correct me if i'm wrong, thanks

    • @mr.l6332
      @mr.l6332 4 ปีที่แล้ว

      I was also wondering if there is an elegant solution for that issue (it also appears earlier in the vid at 3:15). A clumsy solution would be to populate the first couple of elements in dp[] with extra logic attached to avoid negative indexes, and then run the program as normal, but there has to be a better way right?
      For 3:15 the forward-working dp avoids the issue, but I naturally tend to think of problems in the backwards-working way, so I hope someone can share a solution.

    • @mr.l6332
      @mr.l6332 4 ปีที่แล้ว +2

      Oh nvm, he explains in the video that an actual implementation of the pseudocode would require logic statements to make sure (i-x) >= 0 and that values of dp need to be initialized to their respective amounts.

    • @harshmishra7768
      @harshmishra7768 4 ปีที่แล้ว +3

      just write an if condition to avoid out of bounds errors like : if (i - x) >= 0 or maybe x

  • @sharp615
    @sharp615 ปีที่แล้ว

    What is Errichto talking about @15:15? Can anybody please explain?

  • @MehbubulHasanAlQuvi
    @MehbubulHasanAlQuvi 5 ปีที่แล้ว +1

    Thanks a lot. Keep up the good work. Take love

  • @rahulsingh40g
    @rahulsingh40g 4 ปีที่แล้ว +3

    Can somebody help me to provide the code for third problem , by method errichto taught.
    I couldn't understand that

  • @debjit811
    @debjit811 7 หลายเดือนก่อน

    The last problem "Count Coin change" can be solved in a much simpler way using 1D array:
    dp[0] = 1;
    for x in nums:
    for i from (1 to x):
    dp[ i ] += dp[ i - x ];
    print dp[x]

  • @diegonayalazo
    @diegonayalazo 2 ปีที่แล้ว

    Thanks for sharing young Master

  • @pradyumnakatageri3475
    @pradyumnakatageri3475 5 ปีที่แล้ว +4

    Love your videos. When will you make the third video on DP, Looking forward to it.

  • @K_RNDM
    @K_RNDM 2 ปีที่แล้ว

    not getting how you moving from state 17, 1 to 17, 2 for 16:20? if last coin used is of index 1 and sum is 17 then from that point using coin of index 2 how is landing me to state 17, 2?

  • @sumantopal558
    @sumantopal558 5 ปีที่แล้ว +1

    Thanks for video lectures

  • @YashSingh-ir3ec
    @YashSingh-ir3ec 4 ปีที่แล้ว +1

    To avoid Double Counting I think this could work well.
    If we have currently denomination i, then I could make the sum greater than or equal to i using this denomination so that we will have all denominations required for a particular sum in non-decreasing order. This will reduce double counting. So using only one state we could solve this problem i.e sum only.

    • @YashSingh-ir3ec
      @YashSingh-ir3ec 4 ปีที่แล้ว +1

      dp[0] = 0;
      for(int i = 0; i < denominations.size(); i++)
      for(int current_sum=denominations[i]; current_sum

  • @my3m
    @my3m 5 ปีที่แล้ว +13

    How do you come up with relationship?
    for 1...N
    for x in nums
    dp[i] = dp[i-x]

    • @Errichto
      @Errichto  5 ปีที่แล้ว +3

      Just apply what is allowed in the statement. Also, I don't know what part you're refering to. Always put a timestamp.

    • @rafay6821
      @rafay6821 5 ปีที่แล้ว +5

      @errichto at around 4:30 when you provided the dp relation dp[ i ] = dp[ i - x ], could you please say why i-x? What is the justification behind it. Or more specifically what thought process went behind deriving that relation?

    • @neowitcherrivian3594
      @neowitcherrivian3594 4 ปีที่แล้ว +1

      @@Errichto at 3:03 you defined the dp relation to be dp[ i ] += dp[ i - x ], could you please explain how did you come up with it?

    • @cindytrinhsridykhan6375
      @cindytrinhsridykhan6375 4 ปีที่แล้ว +15

      The way I understand it:
      The idea is to go through each element x of the array nums and see how many ways you can come up with if you construct a sum starting with x.
      If we take the example of the video: nums = [1, 2, 3] and N = 4. Assume that we have filled all the elements of dp for i

    • @suryasuresh9330
      @suryasuresh9330 4 ปีที่แล้ว

      @@cindytrinhsridykhan6375 thank you this made a lot of sense! I feel this part of the problem solving is the toughest to come up with. He came up with the answer without really explaining where he got the intuition from

  • @sudheertripathi3882
    @sudheertripathi3882 4 ปีที่แล้ว +1

    Thanks Errichto !!!!!!😊😊😊

  • @Gynormousdish
    @Gynormousdish 5 ปีที่แล้ว

    Great video Errichto! Would love to see the famous egg drop problem.

  • @fbru02
    @fbru02 5 ปีที่แล้ว +2

    This video is great !

  • @shnerdz
    @shnerdz 5 ปีที่แล้ว +2

    love the content, please make videos on backtracking!

  • @sharinganuser1539
    @sharinganuser1539 4 ปีที่แล้ว

    while watching this....i got something in my mind but i don't know if its correct...
    if in a dp you have to make choices....most of them will be either fibonacci , 0/1 knapsack or unbounded knapsack.(how to distinguish which one?)
    1)if order dosen't matter for your choices and how many times u want an item also dosen't matter then its fibo
    2) if order matters and you can take an item only once then its 0/1 knapsack
    3) if order matters , u can take an item any number of time its unbounded knapsack.

  • @CarrotCakeMake
    @CarrotCakeMake 5 ปีที่แล้ว +1

    Nice presentation

  • @sonitushar93
    @sonitushar93 4 ปีที่แล้ว +3

    What if values of array are in double instead of integer then how you will take that sum as indices of dp array?

  • @nsarda
    @nsarda 5 ปีที่แล้ว +3

    Hi Errichto,
    Can you please explain again the part where you changed time complexity from O(n.k^2) to O(n.k).I didn't understand(Around 12:20 in the video) it properly.
    Thanks in advance.
    Also ,please suggest where to practice dp problems to master it.

    • @lichangyu5768
      @lichangyu5768 4 ปีที่แล้ว +4

      It seems bit cutoff. But what he meant is, if we use the lastCoin as the second state, it is impossible going from (17, 2) to (17, 3). Thus you have to count (17, 2) - > (20, 3) and (17, 3) - > (20, 3) separately even (20, 3) is the same state because there are two distinct path leading to that state. However, if you allow the transition (17,2 ) - > (17, 3) by redefining the second state as limit of coin ranged has been used, then you have to count (20, 3) only once because if you go (17, 2) - > (20, 3) or (17, 2) - > (17, 3)- >(20, 3) should leads to the same state(transitivity and thus a cycle). But then you have to redefine all the recursive relationship, which is the usual coin- change algo that you can find online.

    • @nishuone161
      @nishuone161 3 ปีที่แล้ว

      @@lichangyu5768 牛逼,看完视频对那部分还是有点疑惑,看完你的解释我终于悟了。多谢大哥。

  • @amansingh-os9gd
    @amansingh-os9gd 4 ปีที่แล้ว +2

    hey i am not able to follow. where can i see implementation

  • @amolmishra7891
    @amolmishra7891 4 ปีที่แล้ว +1

    should not dp[0]=0 in the min. number of denominations case?

  • @jamilahmedahmed8187
    @jamilahmedahmed8187 5 ปีที่แล้ว

    Thanks you to provide this information

  • @augustinekanyi
    @augustinekanyi 5 ปีที่แล้ว +22

    saw you on JOMA had to subscribe and hit the bell icon!

  • @Vins-pe8mw
    @Vins-pe8mw 4 ปีที่แล้ว +1

    i dont get how you got the sequence 1,0,0,0,0 in min 3:00
    i=1 , then:
    dp[1] += 1-1 + 1-2 + 1-3 = -2
    ?

    • @suryasuresh9330
      @suryasuresh9330 4 ปีที่แล้ว

      hmm good catch, I believe he forgot another condition probably,
      the code makes more sense if there was an if statement that breaks when i - x < 0, that way it doesnt go into the negatives

    • @md.romizulislam7416
      @md.romizulislam7416 4 ปีที่แล้ว

      he didn't complete bro, don't dare to find wrong of a LG
      he was just trying to ease and showing the way to solve , not the solution :)

  • @vatsalsonigara3707
    @vatsalsonigara3707 5 ปีที่แล้ว +1

    Really good video!! Can you please make some video of dp bitmask

  • @lobsanggyatso6280
    @lobsanggyatso6280 4 ปีที่แล้ว +1

    Can u tell me when to call recursive function inside loop or not. I saw in one video that suggest that most often permutation are used with loop

  • @ronnith2405
    @ronnith2405 4 ปีที่แล้ว

    Plz make a series on graph theory

  • @azzzn-m8h
    @azzzn-m8h 2 ปีที่แล้ว

    how does the code for second problems work? i don't get it

  • @blazer511
    @blazer511 5 ปีที่แล้ว +3

    Hi errichto, what exactly do we return when i-x falls out of bounds , below 0?

    • @Errichto
      @Errichto  5 ปีที่แล้ว +6

      It depends on a problem. If it's counting ways to achieve something, then 0 (there are zero ways to get negative sum). If it's maximizing some value, then -INF (so that it wouldn't affect the answer).

    • @blazer511
      @blazer511 5 ปีที่แล้ว +1

      @@Errichto thank you Kamil!

  • @omti
    @omti 5 ปีที่แล้ว +3

    When the next part will be published? :D

  • @vivekpal1004
    @vivekpal1004 5 ปีที่แล้ว +5

    Avoid the double counting.
    Avoid the double counting.

  • @shreyanshsingh2627
    @shreyanshsingh2627 4 ปีที่แล้ว +2

    Could you do a video on linear data structures? Like, standard problems on them and the intuition behind how to solve problems related to them?

  • @dmitrydmitriev2554
    @dmitrydmitriev2554 4 ปีที่แล้ว +1

    What does it means this transition: (17,2) => (17+nums[2],2) 11:35
    17 is the sum need to get by set of cions.
    2 is a last coin in an ordered set. - this is clear.
    But (17+nums[2],2) - this transition is totally unclear, why do the sum changes?
    UPD: Its clear now (sum: 17, last_coin_index: 2).
    than you

    • @dmitrydmitriev2554
      @dmitrydmitriev2554 4 ปีที่แล้ว

      It's looks like transition (sum:17, last_coin: 2) => (sum: 17+2, last coin:2) or (sum: 17+3, last coin: 3). But why do 3 and 2 some times written like nums[2] or nums[3]?

    • @jimmyshenmusic
      @jimmyshenmusic 4 ปีที่แล้ว

      @@dmitrydmitriev2554 I had the similar doubt. I read the leetcode discussion and wrote a summary here. Hope it helps.
      medium.com/@jim.morris.shen/combination-sum-or-coin-change-cd9264a02903?source=friends_link&sk=f071a05acbedc48a1ce9b1f61b5f49ab

  • @sridharbajpai420
    @sridharbajpai420 5 ปีที่แล้ว +1

    make video on segment trees

  • @hakankanplay
    @hakankanplay 5 ปีที่แล้ว +1

    Hey can you make videos concerning bit manipulation questions similar to the ones on leetcode I am having a hard time understanding the intuition to most of these problems.

  • @progamerzzz1237
    @progamerzzz1237 3 ปีที่แล้ว

    hey errichto why did you stop your dp series man.Please continueeee it.We need it

  • @yogendersingh4154
    @yogendersingh4154 5 ปีที่แล้ว +2

    in your first episode of dp :in staircase problem , how you got the intuition that you have to generalize it for i , then how you got the thinking that you have to solve it from i to backward rather than generalizing it from 1st or 0th step to i ? It's a bit confusing for a beginner like me how the thinking pattern deviates from problem to problem .

    • @Errichto
      @Errichto  5 ปีที่แล้ว +6

      We don't go backwards. We go from 1st or 0th.
      And why are you asking here instead of that first episode? ;p

    • @getintodevices1215
      @getintodevices1215 5 ปีที่แล้ว +1

      There are two broad styles of DP, backward and forward. Usually, you can choose whatever feels more intuitive to you.

    • @getintodevices1215
      @getintodevices1215 5 ปีที่แล้ว +1

      So for staircase problem, define f(x) as ways to cover x stairs ahead of us. Then f(x) = f(x - 1) + f(x - 2). Ways to cover x - 1 stairs ahead of us(jump 1 stair) + ways to cover x - 2 stairs ahead of us(Jump two stairs). There can be other ways to think of this and it depends on whatever feels natural to you.

  • @sayan8635
    @sayan8635 3 ปีที่แล้ว

    @errichto can you please provide some read-up resources for forward or push dp?

  • @EzraSchroeder
    @EzraSchroeder ปีที่แล้ว

    @2:14 how do you know dp[0] = 1? I used to be much better at math & even have a B.S. degree in it, but don't remember much.

    • @EzraSchroeder
      @EzraSchroeder ปีที่แล้ว

      I guess maybe the explanation @2:37 is the best way to think about it???

    • @LadderVictims
      @LadderVictims 28 วันที่ผ่านมา

      @@EzraSchroeder do you still have that doubt

  • @Chandansingh374
    @Chandansingh374 5 ปีที่แล้ว +1

    Can u suggest some resources for combinatoric with dp,

  • @wizardOfRobots
    @wizardOfRobots 3 ปีที่แล้ว

    last slide->
    *Avoid double counting
    *Avoid double counting
    You madlad errichto!

  • @codingwithanonymous890
    @codingwithanonymous890 2 ปีที่แล้ว

    can someone please explain forward dp its bit confusing pls

  • @geoffl
    @geoffl 3 ปีที่แล้ว

    for coin change (min) what would happen if you init dp[1..N] = 0?

  • @ivan-e-t5h
    @ivan-e-t5h 4 ปีที่แล้ว

    Does anybody know how to choose between backtracking and dynamic programming - problem's definition are similar how to choose one or another approach?

  • @Makitotutosgamemaker
    @Makitotutosgamemaker 4 ปีที่แล้ว +1

    Thank you genius ! :D

  • @wizardOfRobots
    @wizardOfRobots 3 ปีที่แล้ว

    Was initially confused because the numbers in the example were 1,2,3 . For anyone else confused, take a different set of numbers and you'll understand faster.

  • @aurrum4654
    @aurrum4654 4 ปีที่แล้ว

    Say please, what painting app are you using?

  • @ajr1791ze
    @ajr1791ze 5 ปีที่แล้ว +2

    I 1st like your video then see it.

  • @arpanlayek6405
    @arpanlayek6405 4 ปีที่แล้ว

    how to find the pattern to get the state and recurrsion? Can you please elaborate it?

  • @splytrz
    @splytrz 4 ปีที่แล้ว

    3:28 isn't the first solution wrong? If the array of allowed numbers is, say, [3, 5, 6], then when i = 1 we will try to get dp[1-3] which is out of range.

    • @peepforlearning6058
      @peepforlearning6058 4 ปีที่แล้ว

      i too have same doubt, in c the negative index is set default to zero in an array. i accept an array index start from o, we not deeply understood, a[i] or (a+i) by which we understand, a point to start address of the array, and we save the data to the incremented address only, so +i allow us to point to next element, -1 which denoted as before starting the array address some other point. which will be zero or a garbage value, most compiler says zero, and we don't encounter with any error by using it.

    • @abdelrhmansamir1426
      @abdelrhmansamir1426 4 ปีที่แล้ว +2

      He mentioned that it's a pseudo code code.
      you can use if condition to make sure that you 're not out of boundary that's all.

  • @soumyajeet7809
    @soumyajeet7809 5 ปีที่แล้ว +1

    Really thankful for these wonderful lectures. Btw what would be the rating for the coin change problem or similar problems in CF? And if it were to appear in a DIV 2 contest, will it be A B or C?

    • @Errichto
      @Errichto  5 ปีที่แล้ว +4

      It's hard to rate the difficulty of so standard (well known) problem. I guess it's div2-B.

    • @scofield1154
      @scofield1154 5 ปีที่แล้ว +1

      You can count that famous problems like these will never appear in a contest, at least in this format.
      Its entirely possible to get a problem in a contest which solution requires a similar dp solution to one of these famous problems, but you will never encounter a problem that asks you this kind of a problem in a contest.

    • @getintodevices1215
      @getintodevices1215 5 ปีที่แล้ว

      There are similar problems in CF set as Div 2C, but they have statements which make them harder and also require some observation to arrive at recurrence. For ex, codeforces.com/contest/456/problem/C this problem is well known, but CF version is bit difficult in terms of observing the recurrence.

  • @vairamuthu2748
    @vairamuthu2748 3 ปีที่แล้ว

    why are we not considering double counting in min coin change problem ?

  • @cliid4355
    @cliid4355 3 ปีที่แล้ว

    so the third problem (coin change - ways) is basically two steps of JUMP and ACTUALLY USE

  • @madelineabio9406
    @madelineabio9406 7 หลายเดือนก่อน

    THANK YOU

  • @manjumallesh6932
    @manjumallesh6932 4 ปีที่แล้ว

    @errichto subtitles are covering the algorithms

  • @philosphize
    @philosphize 4 ปีที่แล้ว +1

    Sir can you please say , i have started coding in python but most of people do competitive coding in c++, should i quit python and shift in c++ or
    I should continue my coding in python itself

    • @Errichto
      @Errichto  4 ปีที่แล้ว

      It's ok for beginners and your question was asked thousands of times, use Google next time.

    • @philosphize
      @philosphize 4 ปีที่แล้ว

      @@Errichto Thanks so much sir, i am continuing my coding in python after your reply
      Thank you

    • @philosphize
      @philosphize 4 ปีที่แล้ว

      @@Errichto i did google but i was just thinking if a pro coder like you will advise me then its would be more enthusiastic for me to do so

  • @abhisheksa6635
    @abhisheksa6635 3 ปีที่แล้ว

    One question for the first example as to how we are getting dp[0] = 1 coz truly there is no way to get 0 with [1,2,3] but if we see dp[1] = 1 which sounds reasonable, does this poses a fundamental issue in thinkin.

    • @utkarshtyagi8716
      @utkarshtyagi8716 3 ปีที่แล้ว

      I think dp[0] = 1 refers to the case where we dont choose any number out of the given array, since we can choose a number 0 times or multiple and in case of dp[0] we chose every number 0 times.
      Hope this helps.

  • @di3g04
    @di3g04 4 ปีที่แล้ว +1

    You lost me at the pseudo-code and I've already solved this problem more than once.

    • @AlexandrBorschchev
      @AlexandrBorschchev ปีที่แล้ว

      same, I am very lost at the code. It should be explained much clearly, if the viewer is unfamiliar.

  • @ajr1791ze
    @ajr1791ze 5 ปีที่แล้ว +1

    wouldn't there be three transitions, say suppose we are at index i.
    1 > we can pick it and remain at the same index.
    2 > we can pick it and goes to next index i+1.
    3 > we will not pick it and go to next index i+1.
    I think you gave 1st and 3rd one. what about 2nd.

    • @ariabanazadeh1016
      @ariabanazadeh1016 5 ปีที่แล้ว +3

      Yes but 2 is hidden in 3 and 1.
      Because if we want to pick it and go to next index it's like that we pick it and remain at the same index and
      in the next state, we don't pick it and go to next index.
      Sorry for my bad English,

    • @Errichto
      @Errichto  5 ปีที่แล้ว +3

      @@ariabanazadeh1016 Yup, exactly. 1 and 3 are enough.
      States and transitions create some graph. By adding that second case you would create unnecessary edges. There is path A->B->C and you're trying to add an extra edge A->C that represents the same thing.

    • @ajr1791ze
      @ajr1791ze 5 ปีที่แล้ว

      @@Errichto OK!

    • @ariabanazadeh1016
      @ariabanazadeh1016 5 ปีที่แล้ว +1

      @@Errichto Can you give us a list of good dp problems( I mean with good ideas There is alot of dp problems in code forces and if i sort them by solved count there will be a lot of same ideas or there will be to hard or to easy) so if you have a list of good dp problems please give me. Thank you very much.

  • @shrad6611
    @shrad6611 5 ปีที่แล้ว

    We can also use the nested for loop in a different fashion to avoid the repetition in 3rd problem :
    dp[0] = 1;
    for(int coin : coins){
    for(int i = coin; i

  • @VishalJangid1
    @VishalJangid1 4 ปีที่แล้ว +6

    You wrote "avoid double-counting" twice. Oh, nevermind.

  • @calvinwijaya9706
    @calvinwijaya9706 4 ปีที่แล้ว +4

    dp[i] += dp[i - x] in combination sum will give negative index, so how ?

    • @vaibhavahuja4001
      @vaibhavahuja4001 4 ปีที่แล้ว +5

      add a condition if(i>=x). that is just a pseudocode

  • @getintodevices1215
    @getintodevices1215 5 ปีที่แล้ว

    Errichto, I think you should add a keyword in Video title hinting towards Iterative DP. If someone googles for Iterative DP, your Video has no keywords which will make it any relevant, someone might think it's just yet another recursive DP lecture.

  • @Sharkistas
    @Sharkistas 2 ปีที่แล้ว

    But how about when the SUM... is 41?

  • @sharinganuser1539
    @sharinganuser1539 4 ปีที่แล้ว +1

    it was initially difficult to understand the O(n.k) of coin change....to understand that its good to think with an example...
    lets say coins:1,2,3 and sum=7
    and we are on last block of our grid i.s dp[coin=3][sum=7]
    its enough to think no.of ways to get (sum=7 and coin=2) +(sum=7-3 and coin=3)
    therefore dp[3][7]=dp[2][7]+dp[3][7-3=4] // just take care of base case...and u r good to go.

  • @youtubeuser5822
    @youtubeuser5822 5 ปีที่แล้ว +1

    Please explain DP using recursion.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +2

      I prefer iterative dp. I explained why in the first lecture.

    • @youtubeuser5822
      @youtubeuser5822 5 ปีที่แล้ว

      @@Errichto but considering your viewers you should also explain it using recursion it would be very helpful.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +7

      @@youtubeuser5822 There are hundreds of blogs and videos about recursive dp and barely anything about iterative dp. Why would I do recursion then?

    • @youtubeuser5822
      @youtubeuser5822 5 ปีที่แล้ว

      @@Errichto 😟

    • @pushkarsoni8927
      @pushkarsoni8927 5 ปีที่แล้ว +2

      @@Errichto yup iterative solutions are hard to find, even for graph, trees algos.