1 00:00:01,700 --> 00:00:03,530 Hi, everyone, welcome to this new video. 2 00:00:03,560 --> 00:00:07,110 So in our previous video, we discussed this recursive approach. 3 00:00:07,460 --> 00:00:12,210 So in this video, what we will do, we will try to convert this recursive code to dynamic programming 4 00:00:12,220 --> 00:00:12,520 code. 5 00:00:12,920 --> 00:00:15,770 So let's just start writing the code before writing the code. 6 00:00:15,770 --> 00:00:21,470 Let's define so what we'll do, we will create ADP's since there are N steps. 7 00:00:21,710 --> 00:00:28,460 So we are going to create a deep array of and preferences and the last index will be in and out on will 8 00:00:28,460 --> 00:00:29,320 be deep off. 9 00:00:29,330 --> 00:00:31,530 And so what deep. 10 00:00:31,790 --> 00:00:38,210 I represent DPF, I represent distinct ways to reach index. 11 00:00:38,210 --> 00:00:40,970 I do reach a step, I write so DPF. 12 00:00:40,970 --> 00:00:47,240 I represent the total number of distinct ways to each step I am going. 13 00:00:47,240 --> 00:00:52,830 By this definition, our answer will be DPE often number of unique ways, number of different ways to 14 00:00:52,830 --> 00:00:55,460 reach, step and write. 15 00:00:55,550 --> 00:00:58,600 And we already have the best case, right. 16 00:00:58,610 --> 00:00:59,570 So we have everything. 17 00:00:59,570 --> 00:01:01,490 Let's just start writing the code. 18 00:01:04,440 --> 00:01:05,940 So let's comment about this. 19 00:01:08,370 --> 00:01:12,720 So we need to create a area of size in society and plus one. 20 00:01:14,700 --> 00:01:22,400 Now, let's initialize the best case, so BP of zero will be when I'm standing at the ground level. 21 00:01:22,410 --> 00:01:27,630 So similarly, if you want to reach step one, how many unique ways will be possible? 22 00:01:27,630 --> 00:01:28,500 Only one, right? 23 00:01:28,710 --> 00:01:30,180 By taking a step of one. 24 00:01:33,160 --> 00:01:34,540 Now it's a trade. 25 00:01:39,630 --> 00:01:43,050 And we know the reconciliation, so what is our answer? 26 00:01:43,410 --> 00:01:49,320 I would answer was to reach step, i.e. you can reach from I mean, this one by taking a step of one 27 00:01:49,560 --> 00:01:54,970 or you can reach from a minus to by taking a step of two, and that's it. 28 00:01:55,500 --> 00:01:58,110 And finally, you are going to return your answer. 29 00:01:58,650 --> 00:02:00,570 And our answer was B B of. 30 00:02:00,570 --> 00:02:04,500 And so that will be the complete code. 31 00:02:10,630 --> 00:02:16,810 Now let's discuss the variation for discussion, so in this case, what I'm doing is I am allowed to 32 00:02:16,810 --> 00:02:20,690 take a step of one or take a step of either one or two. 33 00:02:21,040 --> 00:02:25,330 Now, the question can be modified that you can take a step of one, two or three. 34 00:02:25,600 --> 00:02:32,710 So in that case, what you will do, you will add head count steps and minus three. 35 00:02:33,130 --> 00:02:33,580 Right. 36 00:02:33,800 --> 00:02:39,100 Similarly, if the question is you can take a step of one, two, three and four, then you will also 37 00:02:39,100 --> 00:02:40,540 add and minus four here. 38 00:02:40,900 --> 00:02:48,940 And similarly, you will add the P of a minus three here, then DP of a minus four er plus and so on. 39 00:02:49,210 --> 00:02:51,250 So similarly this value can be anything. 40 00:02:51,580 --> 00:02:58,030 So in the question, if the question has been modified that given you need to reach the top basically 41 00:02:58,030 --> 00:03:03,580 and step and you can take a jump of one, two, three, basically you can take a jump of that mix. 42 00:03:03,910 --> 00:03:04,220 Right. 43 00:03:04,720 --> 00:03:12,310 So in this question, the value of KS, basically two in the question, the value of KS to you can take 44 00:03:12,310 --> 00:03:14,610 a jump of either one or two. 45 00:03:14,950 --> 00:03:18,340 But now I'm modifying the question to a general approach. 46 00:03:18,640 --> 00:03:23,710 So given that you can take a jump of gay means, you can take a jump off one, you can take a jump of 47 00:03:23,710 --> 00:03:25,000 two, three, four. 48 00:03:25,870 --> 00:03:28,260 OK, so I have modified the question. 49 00:03:28,690 --> 00:03:35,170 So your problem is your homework is basically trying to modify this code so that this code works for 50 00:03:35,180 --> 00:03:37,860 key and not just one and two. 51 00:03:38,380 --> 00:03:38,820 Right. 52 00:03:39,010 --> 00:03:40,600 So give it a try. 53 00:03:40,810 --> 00:03:42,250 We will discuss the solution. 54 00:03:42,430 --> 00:03:47,980 We will modify this code for General K in our next video so that other guys. 55 00:03:47,980 --> 00:03:49,220 I will see you in the next one. 56 00:03:49,420 --> 00:03:49,960 Thank you.