1 00:00:01,670 --> 00:00:02,390 Hi, everyone. 2 00:00:02,420 --> 00:00:06,580 So in this video, we are going to solve this question, remove consecutive duplicates. 3 00:00:07,220 --> 00:00:12,570 So if this is my string A, B, B, B, C, D, D. 4 00:00:12,950 --> 00:00:16,040 So if this is my string, I need to remove the consecutive duplicates. 5 00:00:16,370 --> 00:00:19,520 So is present consecutively and duplicate. 6 00:00:19,550 --> 00:00:21,610 OK, so consecutive and duplicates. 7 00:00:21,980 --> 00:00:23,360 So we will take only one. 8 00:00:23,390 --> 00:00:24,770 So two is at present. 9 00:00:24,770 --> 00:00:32,150 I will take only one, two, three B's at present, but I will take only one six percent, only one 10 00:00:32,150 --> 00:00:32,450 time. 11 00:00:32,450 --> 00:00:34,770 So C D present twice. 12 00:00:34,820 --> 00:00:37,790 So I will take only one and is present. 13 00:00:37,790 --> 00:00:38,060 So. 14 00:00:39,080 --> 00:00:44,600 So if this is my string A, B, C, Beedie so what will be the output. 15 00:00:44,840 --> 00:00:52,820 So is present E then B's B's Alonzo B C alone C B alone B and these alone. 16 00:00:52,840 --> 00:00:57,900 Sordi So no changes and this string and here we need to take only one. 17 00:00:58,040 --> 00:01:01,640 OK, so if it is presented multiple times we will take only one. 18 00:01:02,270 --> 00:01:08,000 So B is present three times so we will take only one B so I hope you understood the question so we can 19 00:01:08,000 --> 00:01:11,990 solve this question easily with the help of all available since we are learning recursion. 20 00:01:11,990 --> 00:01:13,280 So let's use recursion. 21 00:01:13,280 --> 00:01:15,520 So indication how we can solve this question. 22 00:01:15,530 --> 00:01:18,460 So again, this is my car today. 23 00:01:19,430 --> 00:01:24,370 I will work on this small problem and I will give recursion, this big problem to solve. 24 00:01:24,950 --> 00:01:25,630 So let's see. 25 00:01:25,970 --> 00:01:28,490 So first of all, what I will do this is Rick Perry. 26 00:01:29,300 --> 00:01:32,330 So I will check the character and the first character. 27 00:01:32,750 --> 00:01:37,030 So I will check the character and the first character. 28 00:01:37,400 --> 00:01:41,360 So if they are equal, I to do something in the ultimate. 29 00:01:42,640 --> 00:01:49,390 So if they are not equal, see, there can be two situations, 010 first character, they are equal 30 00:01:49,390 --> 00:01:50,540 or they are not equal. 31 00:01:50,710 --> 00:01:56,500 So if they are not equal, if they are not equality, the Springers be in. 32 00:01:57,790 --> 00:02:00,910 So in this case, B and they are not equal. 33 00:02:01,240 --> 00:02:02,690 So B, they are not equal. 34 00:02:02,710 --> 00:02:05,880 So in that case, what I will do, I will call that equation on this area. 35 00:02:06,850 --> 00:02:12,160 I will call let you guys in on this area because I have done my small amount of work and will do big 36 00:02:12,160 --> 00:02:12,880 amount of work. 37 00:02:13,210 --> 00:02:14,650 So I will call that equation. 38 00:02:15,100 --> 00:02:19,300 So I will call Dacogen and that is input plus one. 39 00:02:20,620 --> 00:02:27,730 Simple, I will let you guys in on this area and this area is basically this is input and this is input 40 00:02:27,730 --> 00:02:29,410 plus one, so I will give input plus one. 41 00:02:29,560 --> 00:02:31,120 Now, if the situation. 42 00:02:32,810 --> 00:02:35,780 If 08 in the first, they are saying so basically. 43 00:02:37,580 --> 00:02:45,740 I have a and then I have BCD and something, so if the first two characters are same, so I told you 44 00:02:45,740 --> 00:02:48,710 we need only one character, we need only one. 45 00:02:48,920 --> 00:02:54,250 So what I will do, I will shift all the characters towards left, just like the previous problem. 46 00:02:54,260 --> 00:02:56,610 I will shift all the characters towards left. 47 00:02:57,320 --> 00:02:58,600 So let's take one example. 48 00:02:58,880 --> 00:03:06,500 So I have this A and then I have B, C, D, D and B, and then I have done so. 49 00:03:06,500 --> 00:03:11,710 In this problem you can see the easy route and the first character the same. 50 00:03:12,080 --> 00:03:18,530 So zero and the first character, if they are same, shift all the characters towards left, just like 51 00:03:18,530 --> 00:03:21,450 the previous problem, the shift, all the characters towards left. 52 00:03:21,830 --> 00:03:28,680 So this will be then B, then C, then D, B so we will shift that also. 53 00:03:29,120 --> 00:03:33,910 So then null and then so this will be our new string. 54 00:03:33,920 --> 00:03:35,420 This will be our new crit bearing. 55 00:03:35,690 --> 00:03:40,910 And then what we need to do, we will call on this area, but we will give input. 56 00:03:41,450 --> 00:03:42,860 So input will remain the same. 57 00:03:43,220 --> 00:03:47,660 So this was in Putera, I will call it, because you're not in Portelli. 58 00:03:47,870 --> 00:03:52,100 So after shifting all the elements towards left, I will call that equation on in Proterra. 59 00:03:52,790 --> 00:03:56,030 So I will call that equation input and not input plus one. 60 00:03:57,200 --> 00:03:58,640 So I hope you understood the question. 61 00:03:59,110 --> 00:04:00,500 So now let's write the code. 62 00:04:00,920 --> 00:04:02,440 So writing the code is very simple. 63 00:04:02,480 --> 00:04:03,710 They are able to function. 64 00:04:03,710 --> 00:04:04,360 It would be void. 65 00:04:04,370 --> 00:04:06,200 I will not return anything. 66 00:04:06,530 --> 00:04:12,920 Let's say the name of the function is remove consecutive duplicate. 67 00:04:16,000 --> 00:04:18,040 So it will take correct barriers and put. 68 00:04:19,550 --> 00:04:28,980 This case is very simple, if my heart is empty, so if that is empty, so if in Port of Zero at of 69 00:04:29,340 --> 00:04:29,970 the original. 70 00:04:33,080 --> 00:04:37,700 So in that case, there is nothing to be deleted, so we will simply have done we will not do anything, 71 00:04:37,710 --> 00:04:38,900 we will simply have done. 72 00:04:42,080 --> 00:04:48,290 So now in the off part, so if the first two characters are different, so if in pataphysical. 73 00:04:50,230 --> 00:04:51,460 And in 2001. 74 00:04:52,870 --> 00:04:55,780 If they are different, if the first two characters are different. 75 00:04:57,470 --> 00:05:02,390 Then I will simply call precaution, so if the first two characters. 76 00:05:06,470 --> 00:05:11,360 So if the zeroth character and the first character, if they are different, if the first character 77 00:05:11,450 --> 00:05:13,220 they are different, then what I will do. 78 00:05:13,490 --> 00:05:18,050 So I have worked on this small problem I have compared to the character of the first group. 79 00:05:18,060 --> 00:05:20,590 But now it's time to call dedication on this idea. 80 00:05:20,990 --> 00:05:25,260 So I will call a question and the question will remove all the duplicates, all and regulatory. 81 00:05:26,180 --> 00:05:28,540 So let's call that a corporate entity with a function. 82 00:05:28,910 --> 00:05:30,560 So remove consecutive duplicate. 83 00:05:32,180 --> 00:05:39,530 And I will do I will pass the idea and put one now in the sales part, the first to criticize him. 84 00:05:40,630 --> 00:05:46,300 So if the first to criticize him, then it's very easy, then I have B, B, C, D. 85 00:05:48,450 --> 00:05:53,430 So if the first two characters are slim, indeed they are slim, then they need to do I need to shift 86 00:05:53,430 --> 00:05:54,960 all the characters towards the left? 87 00:05:56,780 --> 00:06:03,980 So shift all the characters towards left, I have none here, so and so two times A, then B, so B, 88 00:06:03,980 --> 00:06:09,260 B, then suddenly C and B and will also shift null, null. 89 00:06:09,260 --> 00:06:11,300 And we have none at the last also. 90 00:06:11,600 --> 00:06:13,800 So this will be our new area. 91 00:06:14,060 --> 00:06:15,790 This will be our new input area. 92 00:06:16,280 --> 00:06:18,560 And we will call Dacogen on this input only. 93 00:06:18,880 --> 00:06:24,720 OK, so now you can see it is present two times again, experimental times again. 94 00:06:24,950 --> 00:06:27,180 So again, what do will also shift? 95 00:06:27,710 --> 00:06:30,870 So it will become a shift, all the element towards left. 96 00:06:31,160 --> 00:06:37,430 So then we then B, then C, then D, then null then. 97 00:06:37,640 --> 00:06:42,130 And so this will be our new and this will be the input area. 98 00:06:43,010 --> 00:06:44,790 So I will again call the location on this area. 99 00:06:44,810 --> 00:06:48,650 So this time, this time the first two elements are different. 100 00:06:48,660 --> 00:06:50,450 So I will call the equation smaller. 101 00:06:50,840 --> 00:06:58,820 I will call the equation smaller B, B, C, D, and so there's no need to write multiple times because 102 00:06:58,820 --> 00:07:02,610 when the less efficient one will do the work. 103 00:07:03,110 --> 00:07:05,070 So no need to write down multiple times. 104 00:07:05,090 --> 00:07:06,910 So now I will call the equation on this. 105 00:07:07,310 --> 00:07:10,180 So first, two elements are same again shifting and so on. 106 00:07:10,820 --> 00:07:11,780 So we need to shift. 107 00:07:13,450 --> 00:07:18,970 And I write the code for shifting in our previous video, so I equals zero. 108 00:07:20,340 --> 00:07:23,280 And Partovi is not close to only. 109 00:07:26,130 --> 00:07:29,220 I placeless so in Partovi. 110 00:07:31,860 --> 00:07:34,500 Is it was to and Partovi plus one. 111 00:07:37,600 --> 00:07:42,760 So after shifting the element we need to call the election, so do I need to call the equation in Pataudi? 112 00:07:44,130 --> 00:07:45,840 And I think our function will work. 113 00:07:46,380 --> 00:07:51,630 So let's call the function here, see, I am printing the lint and I'm bringing the character ready. 114 00:07:51,930 --> 00:07:56,180 Now, let's call the function remote control to duplicate. 115 00:07:56,190 --> 00:07:57,490 I will pass the input today. 116 00:07:57,540 --> 00:08:03,180 So after removing the consecutive duplicates, I am printing the list again and I am printing the correct 117 00:08:03,180 --> 00:08:03,830 that again. 118 00:08:05,250 --> 00:08:06,950 So I think we did everything fine. 119 00:08:07,290 --> 00:08:08,790 So let's test our function. 120 00:08:13,650 --> 00:08:22,700 So let's say A, B, B, B, C, D, D, E, and basically the total number of characters is nine. 121 00:08:23,490 --> 00:08:27,930 So you can see eight percent two times, but in the output is president only one time. 122 00:08:28,200 --> 00:08:32,400 So B was president twice, but vice president only once see only one. 123 00:08:32,429 --> 00:08:36,659 So when the president was president two times, but now it is only one time. 124 00:08:36,659 --> 00:08:39,679 So he alone, alone and Lelantos five. 125 00:08:41,159 --> 00:08:42,870 So basically our function is working. 126 00:08:43,020 --> 00:08:44,490 So let's test it one more time. 127 00:08:49,190 --> 00:08:58,440 So let's say the importance, ay, ay, ay, and then I have B, C, B, B, C, D and easy. 128 00:08:59,150 --> 00:09:02,390 So let's test whether our output is right or wrong. 129 00:09:03,800 --> 00:09:09,590 So it was present multiple times, but now is present only once. 130 00:09:09,930 --> 00:09:14,220 So then it was busy, so busy then B was present twice. 131 00:09:14,270 --> 00:09:16,390 So be present only once, c once. 132 00:09:16,400 --> 00:09:19,790 Even the one time, the one time it was present twice. 133 00:09:20,090 --> 00:09:27,120 But now it's present only once and the length is seven and for this area discredited Atlantis 14. 134 00:09:27,500 --> 00:09:29,160 So basically our function is working. 135 00:09:29,420 --> 00:09:30,980 So this is it from this video. 136 00:09:30,980 --> 00:09:32,150 I will see you the next one. 137 00:09:33,910 --> 00:09:34,390 Thank you.