1
00:00:01,810 --> 00:00:02,530
Hi, everyone.

2
00:00:02,560 --> 00:00:08,560
So today we are going to solve this problem, remove all our duplicates, character in a string.

3
00:00:08,800 --> 00:00:13,630
OK, so what this problem says is this problem says jus.

4
00:00:15,280 --> 00:00:23,170
The word dissent obligates and let them choose to dissent, duplicates and believed them.

5
00:00:23,200 --> 00:00:27,570
OK, so remember to add dissent and duplicates.

6
00:00:27,620 --> 00:00:28,780
OK, so.

7
00:00:30,320 --> 00:00:36,680
My input will be basically a string and output will also be a string.

8
00:00:38,180 --> 00:00:41,150
And this string will not contain duplicate characters.

9
00:00:41,180 --> 00:00:46,670
OK, so let's consider let us take some input and output example to understand the question.

10
00:00:47,060 --> 00:00:52,940
OK, so here would have to choose, choose to discern, duplicate and delete them.

11
00:00:53,420 --> 00:00:55,960
So these are two different duplicates.

12
00:00:55,970 --> 00:00:57,160
So we will delete them.

13
00:00:57,500 --> 00:01:04,129
So my output will be a B, OK, so Mark will be only now in this case I have to choose two different

14
00:01:04,129 --> 00:01:04,720
duplicates.

15
00:01:05,000 --> 00:01:07,650
So these are two adjacent duplicates.

16
00:01:08,030 --> 00:01:10,310
These are two different duplicates.

17
00:01:10,580 --> 00:01:14,360
And similarly, these are two different duplicates.

18
00:01:14,580 --> 00:01:15,710
So I will remove them.

19
00:01:17,840 --> 00:01:22,520
And my output will be A, B and B, OK, so this is my output.

20
00:01:22,880 --> 00:01:24,290
Now let's see this example.

21
00:01:24,530 --> 00:01:25,860
So this is my input.

22
00:01:26,240 --> 00:01:28,460
These are two adjacent duplicates.

23
00:01:28,470 --> 00:01:32,150
So I will remove them so my output will be empty string.

24
00:01:32,270 --> 00:01:35,660
OK, so my output is basically empty string.

25
00:01:37,320 --> 00:01:38,920
Now, let's consider this example.

26
00:01:39,240 --> 00:01:41,760
So these are two adjacent duplicates.

27
00:01:42,150 --> 00:01:43,670
OK, so what will happen?

28
00:01:43,680 --> 00:01:44,540
I will remove them.

29
00:01:44,880 --> 00:01:47,520
So after removing them, what will be my string?

30
00:01:47,730 --> 00:01:50,430
So my string will become B, B?

31
00:01:50,760 --> 00:01:57,000
Now, again, these are two adjacent characters, so I will remove them so my output will be empty.

32
00:01:57,000 --> 00:01:57,420
String.

33
00:01:58,150 --> 00:02:01,470
OK, Margaret will be an empty string that are disconcert.

34
00:02:01,480 --> 00:02:02,820
Then one more example.

35
00:02:02,820 --> 00:02:04,270
Let us consider this example.

36
00:02:04,290 --> 00:02:09,330
OK, so these are two different characters so I will remove them.

37
00:02:09,690 --> 00:02:11,750
These are two different characters.

38
00:02:11,760 --> 00:02:12,690
I will remove them.

39
00:02:13,050 --> 00:02:15,000
These are two different characters.

40
00:02:15,180 --> 00:02:16,110
I will remove them.

41
00:02:16,350 --> 00:02:17,670
So what will be my string.

42
00:02:17,670 --> 00:02:21,390
So my string will be m i again.

43
00:02:21,390 --> 00:02:23,790
I again I again I.

44
00:02:24,100 --> 00:02:26,340
OK, so what will happen now.

45
00:02:26,490 --> 00:02:30,590
So these are two different characters so I will remove them.

46
00:02:30,930 --> 00:02:33,030
These are two adjacent characters.

47
00:02:33,030 --> 00:02:33,930
I will remove them.

48
00:02:34,080 --> 00:02:37,370
So basically my output will be m OK.

49
00:02:37,560 --> 00:02:39,230
So I hope you understood this question.

50
00:02:39,570 --> 00:02:41,750
So this question is basically pleasant only.

51
00:02:41,850 --> 00:02:42,080
Good.

52
00:02:42,300 --> 00:02:45,200
OK, so let us understand this example also.

53
00:02:46,140 --> 00:02:50,790
So I have this string A, B, B, a, c, a.

54
00:02:51,090 --> 00:02:55,260
OK, so these are two different characters, so I will remove them.

55
00:02:55,290 --> 00:02:56,520
So what would be my string.

56
00:02:56,520 --> 00:02:58,850
It will be a a c e.

57
00:02:59,190 --> 00:03:04,900
Now again, these are two distinct characters so I will remove them so I will become CI a..

58
00:03:04,920 --> 00:03:06,280
So this is my output.

59
00:03:06,300 --> 00:03:09,330
OK, you can see, see is the output.

60
00:03:09,660 --> 00:03:13,050
OK, so we have to remove the word just ten equal letters.

61
00:03:13,890 --> 00:03:16,440
OK, so two different letters.

62
00:03:16,440 --> 00:03:18,380
We will find out and then we will include.

63
00:03:19,050 --> 00:03:21,000
OK, so you can read this line.

64
00:03:21,300 --> 00:03:24,190
So we will repeatedly make a duplicate removals.

65
00:03:24,210 --> 00:03:30,000
OK, we will remove duplicates on string until we no longer can.

66
00:03:30,060 --> 00:03:34,170
OK, so now let's see how we can solve this question.

67
00:03:35,300 --> 00:03:40,760
So the very simple approach and the very good approach to solve this question is with the help of a

68
00:03:40,760 --> 00:03:41,090
map.

69
00:03:41,300 --> 00:03:44,210
OK, so how we will take the help of a map.

70
00:03:44,570 --> 00:03:45,800
So let us consider.

71
00:03:47,200 --> 00:03:48,190
This example only.

72
00:03:49,220 --> 00:03:53,060
OK, so let us consider this example so.

73
00:03:55,100 --> 00:04:04,430
I have this string and I is is A is is A, B, B, I, so I have this string.

74
00:04:04,760 --> 00:04:08,130
So the very good approach to solve this problem is with the help of a stick.

75
00:04:08,150 --> 00:04:11,570
So what I can do, what I will do, so I will have a string.

76
00:04:11,670 --> 00:04:15,350
So initially my stake will be empty and the state will be of character.

77
00:04:15,470 --> 00:04:17,930
OK, so I will have a stack of characters.

78
00:04:19,649 --> 00:04:21,390
Now, I would like to draw the string.

79
00:04:21,420 --> 00:04:23,900
OK, so now let's get it over this string.

80
00:04:24,420 --> 00:04:27,570
So the first character is M and my stake is empty.

81
00:04:27,780 --> 00:04:29,820
Since the stake is empty, we will push.

82
00:04:30,130 --> 00:04:32,680
OK, so here comes my first rule.

83
00:04:32,760 --> 00:04:33,700
What is the first rule?

84
00:04:33,960 --> 00:04:37,650
So if the stake is empty, nest egg empty, then push.

85
00:04:38,610 --> 00:04:41,570
OK, e-TAG and President Bush, so this is my first full.

86
00:04:43,130 --> 00:04:45,110
Now, I will come here.

87
00:04:45,150 --> 00:04:48,590
I so now steak is not empty, so this is not the case.

88
00:04:48,620 --> 00:04:52,120
So I will come to situation number two, OK, steak is not empty.

89
00:04:52,700 --> 00:04:57,040
Now compare I with m OK, so these two are different.

90
00:04:57,050 --> 00:04:58,900
That means I do not have to remove anything.

91
00:04:58,910 --> 00:05:05,840
So what I will do, I will push I so what I'm doing here compared let's say the name of the string is

92
00:05:05,840 --> 00:05:08,030
E to compare E of A.

93
00:05:09,360 --> 00:05:11,720
With the top of the stick.

94
00:05:11,760 --> 00:05:19,720
OK, so I'm comparing a with the top of the stack basically stack top and if these two are not equal.

95
00:05:19,740 --> 00:05:23,980
OK, so if each US is not equal, so stagnant up, then again, Bush.

96
00:05:24,150 --> 00:05:25,890
OK, so I am pushing.

97
00:05:25,890 --> 00:05:26,400
I hear.

98
00:05:27,810 --> 00:05:37,740
OK, so now as now the situation will be static is not empty and the top basically of ibises is not

99
00:05:37,740 --> 00:05:39,890
equal to not dubstep not is I.

100
00:05:40,080 --> 00:05:43,510
So I will push through as will go inside now.

101
00:05:43,550 --> 00:05:47,970
S ok so S and s nowadays image.

102
00:05:48,240 --> 00:05:50,930
So this condition is not true, this condition is not true.

103
00:05:50,940 --> 00:05:53,030
So I can do condition number three.

104
00:05:53,370 --> 00:05:56,340
So if there is a match then pop.

105
00:05:58,530 --> 00:06:01,140
If there's a match, then pop and move forward.

106
00:06:02,800 --> 00:06:04,270
OK, so very simple.

107
00:06:04,870 --> 00:06:06,760
So what I will do, I will pop from the.

108
00:06:07,210 --> 00:06:10,920
So let us pop from this track and move forward.

109
00:06:12,460 --> 00:06:13,130
Very simple.

110
00:06:13,780 --> 00:06:14,230
Now.

111
00:06:15,340 --> 00:06:22,450
I and I, again, condition number three will be executed, there is a match if there's a match up and

112
00:06:22,450 --> 00:06:23,080
move forward.

113
00:06:23,350 --> 00:06:26,230
So I will pop and I will move forward.

114
00:06:28,050 --> 00:06:32,550
Now, compare s with M, so these are different s and are different.

115
00:06:32,580 --> 00:06:34,510
So basically this condition will be executed.

116
00:06:34,740 --> 00:06:38,220
I will push as so my stake will be.

117
00:06:38,220 --> 00:06:43,110
So let's say this is my steg, so I have M and I will push.

118
00:06:43,360 --> 00:06:51,510
So that is s OK now again so s and top they are equal if they're equal.

119
00:06:51,660 --> 00:06:53,310
So pop and move forward.

120
00:06:54,960 --> 00:06:57,840
I and they are different than Bush I.

121
00:06:58,640 --> 00:07:03,270
OK, so B b and they are different than Bush B.

122
00:07:04,790 --> 00:07:12,470
Again, B, so B and B, they all seem so conditioned, three, pop and move forward, so let s pop.

123
00:07:13,850 --> 00:07:14,780
And move forward.

124
00:07:16,190 --> 00:07:25,280
So I and I, they all seem so conditioned, but try and move forward so pop and move forward, OK,

125
00:07:25,290 --> 00:07:29,470
so when we will reach the end of the string, so this is basically the end of the string.

126
00:07:29,630 --> 00:07:30,800
So virtually my answer.

127
00:07:30,800 --> 00:07:33,000
So my answer will be present inside the stack.

128
00:07:33,530 --> 00:07:35,380
So my answer is basically am.

129
00:07:36,740 --> 00:07:38,180
And M is the right answer.

130
00:07:38,990 --> 00:07:42,560
OK, let us consider one more example to understand it better.

131
00:07:44,050 --> 00:07:44,980
OK, so.

132
00:07:46,750 --> 00:07:49,270
Let's consider this example a BBC.

133
00:07:51,160 --> 00:07:57,800
OK, so I have this string A, B, B, E, C and E.

134
00:07:58,960 --> 00:08:01,940
OK, so I have this track.

135
00:08:03,100 --> 00:08:04,720
OK, so now let's hydrate.

136
00:08:05,970 --> 00:08:08,100
So my steak is empty.

137
00:08:08,130 --> 00:08:15,480
The steak is empty, we can directly push now B, so B and E, they are different than Bush B.

138
00:08:16,490 --> 00:08:25,170
Now be so be and be stacked up and the current element equal, so I will pop and move forward, so pop

139
00:08:25,940 --> 00:08:26,900
and move forward.

140
00:08:28,210 --> 00:08:34,419
So easy and a stacked up and current vertical, then pop and move forward.

141
00:08:34,450 --> 00:08:40,280
So I will pop and I will move forward now see and my stomach is empty.

142
00:08:40,299 --> 00:08:43,120
So at this point, my stomach is empty.

143
00:08:43,130 --> 00:08:44,280
So the steak is empty.

144
00:08:44,290 --> 00:08:45,160
I will push.

145
00:08:45,160 --> 00:08:47,080
See, OK then.

146
00:08:47,980 --> 00:08:51,660
So compared with the stacked up, they are different than Bush.

147
00:08:53,470 --> 00:08:55,560
Then I will reach the end of the string.

148
00:08:56,110 --> 00:08:58,450
OK, so I will reach the end of the string.

149
00:08:58,600 --> 00:09:00,250
And now my answer is this one.

150
00:09:01,320 --> 00:09:07,650
So basically, when we will pop the element, he will come first and then he will come first, but then

151
00:09:07,650 --> 00:09:08,790
I have to reverse this.

152
00:09:08,820 --> 00:09:10,680
OK, so I will reverse this.

153
00:09:11,310 --> 00:09:15,360
And my answer will be, see, OK, so this is the correct answer.

154
00:09:16,110 --> 00:09:20,420
OK, so when I will pop, it will come out first, then she will come out first.

155
00:09:20,580 --> 00:09:25,830
So to get the answer, to get the answer, I have to apply the reverse operation.

156
00:09:25,860 --> 00:09:27,190
Then my answer will come out to be.

157
00:09:28,410 --> 00:09:30,720
OK, so I hope you understood this question.

158
00:09:31,290 --> 00:09:33,480
So what will be the time and the space complexity.

159
00:09:33,960 --> 00:09:40,470
So basically the time complexity we are just getting over the time complexities when and similarly the

160
00:09:40,470 --> 00:09:43,830
space complexities big off and we are creating stack.

161
00:09:44,010 --> 00:09:45,990
That's why the space complexity.

162
00:09:46,360 --> 00:09:50,220
OK, so if you have understood this question now, let us write the code.

163
00:09:53,380 --> 00:09:59,980
OK, so first of all, what we have to do, we have to create a stack of characters, OK, and let's

164
00:09:59,980 --> 00:10:04,090
say the name is now what we have to do, we have to iterate over the string.

165
00:10:05,220 --> 00:10:07,500
OK, so let's go straight over the string.

166
00:10:10,030 --> 00:10:13,330
So I called societal iList, and he says.

167
00:10:15,330 --> 00:10:16,410
And they placeless.

168
00:10:18,090 --> 00:10:23,900
OK, so condition number one, what is the condition, number one, if Steg is empty, then we can directly

169
00:10:23,910 --> 00:10:24,300
push.

170
00:10:24,720 --> 00:10:26,610
OK, so if a steak is empty.

171
00:10:29,530 --> 00:10:34,600
If there's anybody we can barely push or there is one more condition for pushing.

172
00:10:34,630 --> 00:10:35,200
You can see.

173
00:10:36,420 --> 00:10:42,360
OK, so we have two conditions for pushing these two other conditions for pushing the element, and

174
00:10:42,360 --> 00:10:48,900
this condition is for popping the element so the steak is empty or the current element is not close

175
00:10:48,900 --> 00:10:50,790
to the stacked up, then push.

176
00:10:51,660 --> 00:10:58,170
So I can see if the current element, which is Alphie, if the current element is not close to stack

177
00:10:58,180 --> 00:11:03,170
top element, so stacked up element, then what I have to do, I have to simply push.

178
00:11:03,210 --> 00:11:04,710
OK, so Astarte push.

179
00:11:06,000 --> 00:11:06,630
Alfy.

180
00:11:08,560 --> 00:11:14,800
Now, in the last part, what they will do will simply pop up and move forward so as to pop and move

181
00:11:14,800 --> 00:11:15,310
forward.

182
00:11:15,370 --> 00:11:18,580
OK, so from moving forward, I have written C++ here.

183
00:11:20,340 --> 00:11:26,500
Now, finally, what will happen, so there is strength, so now let us construct our answer.

184
00:11:27,360 --> 00:11:29,250
So initially my answer is empty.

185
00:11:29,670 --> 00:11:32,220
OK, so I'm listing initially my answer is and listing.

186
00:11:32,460 --> 00:11:33,530
Now you can see here.

187
00:11:34,080 --> 00:11:35,430
So how to get answered.

188
00:11:35,970 --> 00:11:38,490
So my answer is present inside this stack.

189
00:11:38,970 --> 00:11:44,100
OK, so what I will do, I will pop every element outside the step toward popping the element.

190
00:11:44,100 --> 00:11:50,790
I will like I will pop every element from the stack so my string will become easy and then I will reverse

191
00:11:50,790 --> 00:11:52,240
the string to get the answer.

192
00:11:52,300 --> 00:11:53,960
OK, so I have to reverse.

193
00:11:53,970 --> 00:11:57,290
Remember, now let's remove the element from the stack.

194
00:11:57,300 --> 00:12:02,400
So while Steg is not empty, but I have to do I have to pop element.

195
00:12:03,630 --> 00:12:06,720
So basically Sadaat pushback.

196
00:12:10,380 --> 00:12:14,130
Alphie, sorry, I thought I'd push back top.

197
00:12:15,900 --> 00:12:19,920
So after getting the element from the top of the stick, we will pop that element.

198
00:12:19,950 --> 00:12:20,370
OK.

199
00:12:21,650 --> 00:12:27,830
So while steak is not empty, I'm getting the topmost element and then I am popping that element.

200
00:12:28,310 --> 00:12:33,950
Now, finally, what we have to do, we have to apply the reverse operation so far, reversing either

201
00:12:34,130 --> 00:12:36,920
build, function, reverse, so reverse onslaught begin.

202
00:12:38,160 --> 00:12:46,110
I am reversing this string, so reverse order to begin karma, so God and I have to give 2.0 beginning

203
00:12:46,150 --> 00:12:46,830
and appointer.

204
00:12:46,890 --> 00:12:50,690
OK, so to iterators and finally the return diaper's string.

205
00:12:50,700 --> 00:12:52,360
So I will return my answer.

206
00:12:53,110 --> 00:12:57,660
OK, so let's run code and then we will try to submit our code.

207
00:13:00,140 --> 00:13:01,670
OK, so now let's admit.

208
00:13:05,560 --> 00:13:09,040
OK, so our goal is working fine, our goal is 100 percent correct.

209
00:13:09,430 --> 00:13:13,840
OK, so basically the same question is also president on Heckerling.

210
00:13:13,960 --> 00:13:17,590
OK, so Gorenc is also a very good website if we want to prepare.

211
00:13:17,800 --> 00:13:19,440
So this is exactly the same question.

212
00:13:19,450 --> 00:13:22,210
The name of the question is super produced a string, OK.

213
00:13:24,490 --> 00:13:28,720
So now let us summiteer also, so I'm copping the gold.

214
00:13:32,730 --> 00:13:34,350
And let's put the gold here.

215
00:13:36,110 --> 00:13:40,070
OK, so this is String S, so we have to change the name string.

216
00:13:40,310 --> 00:13:42,180
OK, so here the name of the string is a.

217
00:13:42,540 --> 00:13:44,630
So that's why I have to change the name of the string.

218
00:13:45,290 --> 00:13:49,160
OK, so now let us first we will run code and then we will submit.

219
00:13:52,720 --> 00:13:58,150
OK, so I forgot to tell you one thing, so here you can, if you will, read the question.

220
00:13:58,520 --> 00:14:06,100
So the question is, so the question is you have to print emplacing, OK, so I have to print these

221
00:14:06,100 --> 00:14:06,390
things.

222
00:14:06,450 --> 00:14:11,060
What can I do here is so first of all, I will check the size of it.

223
00:14:11,350 --> 00:14:13,080
So if the size of it.

224
00:14:13,080 --> 00:14:16,300
So if you're not sorry if I said what size.

225
00:14:19,030 --> 00:14:24,100
Equal, equal zero, basically, the strength is empathy then would have to return.

226
00:14:24,490 --> 00:14:26,540
So I have to return empty string.

227
00:14:26,820 --> 00:14:29,150
OK, so we can copy from here.

228
00:14:30,370 --> 00:14:32,140
So I have to return empty string.

229
00:14:35,240 --> 00:14:40,220
If that if the size of this string is zero of the size of our own zero, basically this thing is empty,

230
00:14:40,220 --> 00:14:41,780
then I will return empty string.

231
00:14:47,930 --> 00:14:52,000
OK, so these are the simple test cases, so our court passes on a simple test cases.

232
00:14:52,040 --> 00:14:53,660
Now let us try to submit our call.

233
00:14:55,500 --> 00:14:58,170
So there are 15 test cases on knackering.

234
00:15:00,560 --> 00:15:03,610
OK, so our goal is working on all the test cases.

235
00:15:03,650 --> 00:15:05,990
OK, so our goal is working.

236
00:15:09,440 --> 00:15:15,470
Now, the time and the space complexity we have already discussed, so basically the time, complexity

237
00:15:15,480 --> 00:15:17,370
and these are the time and the space complexity.

238
00:15:17,750 --> 00:15:24,350
So what we can do here is we can optimize this space complexity to the order of one, OK?

239
00:15:24,620 --> 00:15:27,610
We can optimize the space complexity to the order of one.

240
00:15:27,920 --> 00:15:28,820
How so?

241
00:15:28,820 --> 00:15:36,020
Basically what we will do so here, what we are doing here is so here in this cold, in this cold,

242
00:15:36,020 --> 00:15:39,200
what we are doing, we are creating stack explicitly.

243
00:15:39,260 --> 00:15:44,660
OK, now what we can do, we will write code in such a manner that our code will work as a steck.

244
00:15:46,010 --> 00:15:47,780
Basically, what is the property of us?

245
00:15:48,050 --> 00:15:51,220
So instead, I have only one point, which is the top point.

246
00:15:51,330 --> 00:15:56,300
OK, so I have a pointer top and this top window is doing all that thing.

247
00:15:56,580 --> 00:16:02,090
OK, if I'm popping the element at this point, I will come down and if I am pushing the Aylwin this

248
00:16:02,240 --> 00:16:03,390
point, they will come up.

249
00:16:03,680 --> 00:16:05,530
So basically the stake is melting.

250
00:16:05,540 --> 00:16:06,900
It is just appointer.

251
00:16:07,730 --> 00:16:09,980
So what I will do, I will maintain appointer.

252
00:16:09,980 --> 00:16:15,920
I will maintain aspect of pointer and then we can write this code without explicitly creating a stick.

253
00:16:16,190 --> 00:16:17,630
So for example, what I will do.

254
00:16:18,440 --> 00:16:19,970
So let us consider this example.

255
00:16:19,970 --> 00:16:21,420
Only ABC.

256
00:16:21,500 --> 00:16:27,810
So I have this pointer A B, so I have this string abebe e, c, e.

257
00:16:28,340 --> 00:16:30,200
OK, now what I'm doing here.

258
00:16:31,890 --> 00:16:37,560
So initially, my stack pointer is here, so when I come here, what did I see?

259
00:16:37,590 --> 00:16:40,910
If the stack is empty, then push, OK?

260
00:16:41,160 --> 00:16:45,540
And then first of all, this checkpoint, I will come here and then I will push.

261
00:16:45,810 --> 00:16:50,240
OK, then I will compare B with this stack top pointer.

262
00:16:50,520 --> 00:16:57,570
So basically I will create a stack of pointer and this pointer stack pointer, it will be initially

263
00:16:57,570 --> 00:16:58,170
minus one.

264
00:16:58,950 --> 00:17:04,890
If I have to push the element which I will do so I will do stack pointer plus plus and then I will push

265
00:17:04,890 --> 00:17:10,200
the element of first let me write the code and then I will explain it to you so that you can understand

266
00:17:10,200 --> 00:17:11,609
it better with the help of code.

267
00:17:11,640 --> 00:17:11,970
OK.

268
00:17:13,920 --> 00:17:15,540
So will write very similar called.

269
00:17:17,060 --> 00:17:18,800
So first, let us commend this good.

270
00:17:21,200 --> 00:17:27,109
So our goal will be very similar, but what we are trying to do here is so I am trying to stimulate.

271
00:17:29,380 --> 00:17:30,460
In places like.

272
00:17:33,390 --> 00:17:39,950
So first, what we are doing, we are trading over this string, but first of all, I have created this

273
00:17:39,950 --> 00:17:42,860
is so greetings deck means basically appointer.

274
00:17:43,200 --> 00:17:47,400
So I have this deck pointer, which will be initially minus one.

275
00:17:47,860 --> 00:17:49,820
OK, so empty means minus one.

276
00:17:50,130 --> 00:17:54,360
So I have to point out which is initially minus one now radarscope it is called.

277
00:17:55,740 --> 00:18:00,240
OK, so I'm copying this code now, I'm meditating over that.

278
00:18:00,570 --> 00:18:03,870
So if Stack is empty, stack empty means.

279
00:18:05,120 --> 00:18:06,710
Standpoint, that is minus one.

280
00:18:06,740 --> 00:18:10,230
OK, so stack and stack, pointless minus one.

281
00:18:10,730 --> 00:18:13,190
So if stack pointer is minus one.

282
00:18:15,250 --> 00:18:20,650
OK, so this is the condition now, the second condition, if the current element is not close to the

283
00:18:20,650 --> 00:18:21,590
topmost element.

284
00:18:21,730 --> 00:18:23,510
Now how to get topmost element.

285
00:18:24,040 --> 00:18:26,150
So basically we have stack pointer for that.

286
00:18:26,860 --> 00:18:29,530
OK, so aof stack pointer.

287
00:18:32,360 --> 00:18:39,950
OK, now let us see, it's not Bush, we are pushing the element, OK, so for pushing the limit, what

288
00:18:39,950 --> 00:18:41,730
we will do, we will.

289
00:18:41,990 --> 00:18:44,470
We are pushing the current element so far, pushing the limit.

290
00:18:44,550 --> 00:18:48,770
First we have to incrementalists pointer and then we will push.

291
00:18:48,800 --> 00:18:52,640
OK, so for pushing off Stack pointed.

292
00:18:54,540 --> 00:18:56,590
We are pushing the current element.

293
00:18:56,670 --> 00:18:58,600
OK, we are pushing the current element.

294
00:18:58,890 --> 00:18:59,590
Now, let's see.

295
00:18:59,760 --> 00:19:03,000
So here in the old part, what we are doing, we are popping the element.

296
00:19:03,000 --> 00:19:05,520
So popping means stack pointer, minus, minus.

297
00:19:07,370 --> 00:19:15,080
OK, winter minus minus, then what we are doing, so we are taking a strong answer now let's take answer

298
00:19:15,080 --> 00:19:15,380
here.

299
00:19:16,700 --> 00:19:22,730
Which is initially empty, and then we are creating our answer from the spec element present inside

300
00:19:22,730 --> 00:19:23,230
this deck.

301
00:19:23,480 --> 00:19:26,720
OK, so how many elements are present inside this deck?

302
00:19:27,780 --> 00:19:29,860
So stack pointer will tell us.

303
00:19:29,880 --> 00:19:35,010
So these are the number of elements which are present inside this deck and I placeless.

304
00:19:36,130 --> 00:19:40,050
Now, let us construct our answer, so I said our pushback got most relevant.

305
00:19:40,130 --> 00:19:42,340
OK, so we are pushing elements.

306
00:19:43,570 --> 00:19:45,100
So it will be basically.

307
00:19:47,300 --> 00:19:55,870
It will be if I OK, and here we do not need to reverse anything, so we will likely have done our answer.

308
00:19:58,870 --> 00:20:00,790
So now let us try to submit this call.

309
00:20:02,970 --> 00:20:04,980
OK, so our code is working fine.

310
00:20:06,280 --> 00:20:09,520
OK, so what is the time and space complexity of this cold?

311
00:20:11,620 --> 00:20:18,460
So basically, the time complexities, Lynnette, and here, the space complexities my violent, because

312
00:20:18,460 --> 00:20:23,350
we are not creating a nest egg, we are trying to simulate the stack in place.

313
00:20:24,290 --> 00:20:26,210
OK, so let's see how this code is working.

314
00:20:26,230 --> 00:20:27,480
OK, I will try.

315
00:20:27,490 --> 00:20:29,560
I will tighten the code on this example.

316
00:20:30,550 --> 00:20:41,740
So I have this example A, B, B, A, C and A, OK, now this line stack pointer is minus.

317
00:20:41,740 --> 00:20:43,240
OK, so these are the indexes.

318
00:20:43,270 --> 00:20:47,040
Zero, one, two, three, four and five.

319
00:20:47,080 --> 00:20:48,040
These are the indexes.

320
00:20:48,070 --> 00:20:50,550
OK, so Stack won't lose initially minus one.

321
00:20:50,920 --> 00:20:52,940
So suppose this is minus one.

322
00:20:53,290 --> 00:20:56,650
So initially this is my stack pointer.

323
00:20:56,650 --> 00:20:58,400
ESP means stack pointer, ok.

324
00:20:59,140 --> 00:21:03,490
Now what we are doing we are iterating already if the pointer is minus one.

325
00:21:04,430 --> 00:21:06,070
So we are getting all the idea.

326
00:21:06,090 --> 00:21:11,260
So this is the value of a OK, so I decided OK, so this is the value of.

327
00:21:11,770 --> 00:21:13,330
So first we are checking effect.

328
00:21:13,360 --> 00:21:16,420
Pointer is minus on the stack is empty just like above.

329
00:21:16,570 --> 00:21:18,610
So the stack pointers minus one.

330
00:21:18,610 --> 00:21:23,680
Yes it is then stack pointer plus plus and push the element.

331
00:21:23,680 --> 00:21:30,370
So stack pointer plus plus that means stack pointer removed from here standpoint will come here.

332
00:21:31,620 --> 00:21:39,600
OK, and then, Ágúst, that point, that is IAFIS, so basically replace a with a look now I placeless

333
00:21:39,660 --> 00:21:41,040
so I will come here.

334
00:21:42,670 --> 00:21:50,620
Now, be OK, so standpoint does not my Nesson, then I'm comparing the current element with the element

335
00:21:50,620 --> 00:21:51,990
present at the top of the stack.

336
00:21:52,000 --> 00:21:55,600
So the current element is B and element present at the top of the staircase.

337
00:21:55,960 --> 00:22:02,530
However, because you can see stack pointer is pointing towards A, so B and E they are different.

338
00:22:02,860 --> 00:22:08,080
If they are different, stack went up plus plus basically we are pushing the element so remove.

339
00:22:09,060 --> 00:22:16,540
Standpoint plus, plus and then push the element to replace B with B, now A plus plus.

340
00:22:17,100 --> 00:22:20,820
So I will come here now compare the current elements.

341
00:22:20,820 --> 00:22:25,790
So I'm comparing the current element with the top last element of the stack.

342
00:22:26,190 --> 00:22:31,970
So I'm comparing the current element with the topmost element of the stack.

343
00:22:32,400 --> 00:22:38,590
So they are saying if they are same standpoint, minus minus to the stack pointer.

344
00:22:38,610 --> 00:22:39,720
Welcome here.

345
00:22:40,890 --> 00:22:47,160
Stack pointer, minus minus stack point only, come here, so remove this and I will do a placeless.

346
00:22:49,400 --> 00:22:56,130
OK, now compare the top most now compare the current element with the topmost element of the stack.

347
00:22:56,510 --> 00:22:57,800
So there is a match.

348
00:22:57,830 --> 00:23:02,950
OK, again, there is a match, so I will lose track of minus minus here.

349
00:23:02,960 --> 00:23:09,310
I am comparing the current element with the topmost element of this track, which is a.

350
00:23:09,380 --> 00:23:11,940
So there is a match stack pointer minus minus.

351
00:23:12,560 --> 00:23:19,130
So stack pointer remove stack pointer from here and again it will point towards minus minus.

352
00:23:19,220 --> 00:23:20,730
So this is my stack pointer.

353
00:23:21,350 --> 00:23:24,300
OK, now I placeless so I will come here.

354
00:23:24,770 --> 00:23:28,310
So this is, I know the when there is minus one.

355
00:23:28,340 --> 00:23:31,640
Basically the stack is empty so the stack is empty.

356
00:23:31,640 --> 00:23:37,300
We can directly push so far pushing first we have to increment and then we will push the element.

357
00:23:37,610 --> 00:23:38,720
So increment.

358
00:23:39,050 --> 00:23:40,930
So stack pointer will come here.

359
00:23:41,000 --> 00:23:41,810
So remove it.

360
00:23:41,900 --> 00:23:46,400
So this is stack pointer and what we are pushing the element.

361
00:23:46,400 --> 00:23:48,440
So aztek pointer is alphie.

362
00:23:48,680 --> 00:23:52,760
So replace this E with C, so C will come here.

363
00:23:54,070 --> 00:24:00,900
OK, now I placeless, so this is a now compare the current element with the topmost element.

364
00:24:01,180 --> 00:24:06,280
So this is stack pointer and this is the topmost element, which is basically C compare it with the

365
00:24:06,280 --> 00:24:12,310
C, so they are different stacked one plus plus basically we will push the element to stack one toplessness.

366
00:24:12,320 --> 00:24:16,450
So step removed from here and this will become stack pointer.

367
00:24:17,020 --> 00:24:20,020
And for pushing the element replace B with A.

368
00:24:21,140 --> 00:24:28,040
OK, replace me with a then we will reach the end of the string, so after reaching the end of the string,

369
00:24:28,040 --> 00:24:30,590
I am constructing my answer and what I am doing.

370
00:24:30,920 --> 00:24:34,800
So I am I am starting from zero till stack pointer.

371
00:24:34,820 --> 00:24:36,220
We will push the limits.

372
00:24:36,230 --> 00:24:38,170
So what is the value standpoint?

373
00:24:38,330 --> 00:24:40,460
What a value point that is basically one.

374
00:24:41,030 --> 00:24:42,570
So stack pointer is one.

375
00:24:43,070 --> 00:24:49,520
So what I am doing starting from zero point also basically starting from zero point which is one, so

376
00:24:49,520 --> 00:24:50,750
basically zero and one only.

377
00:24:51,170 --> 00:24:55,430
I am pushing the elements of I inside the answer that string.

378
00:24:55,430 --> 00:24:57,410
It has been what if it has been modified.

379
00:24:57,680 --> 00:24:59,450
So these are at zero.

380
00:24:59,450 --> 00:25:01,100
I have three add one.

381
00:25:01,130 --> 00:25:04,680
I have a so I will push three and a.

382
00:25:04,710 --> 00:25:07,120
So at index zero I have C.

383
00:25:07,160 --> 00:25:12,720
I had the next one I have E and then I told you there is no need to reverse.

384
00:25:12,740 --> 00:25:16,910
OK, so we are currently getting our answer here so there is no need to reverse.

385
00:25:17,300 --> 00:25:20,810
And this is my answer second and then I am returning my answer.

386
00:25:21,140 --> 00:25:24,850
OK, so I know initially this is very overwhelming.

387
00:25:24,860 --> 00:25:28,330
OK, so for you, I know I have to go into the same situation.

388
00:25:28,340 --> 00:25:29,540
This is very overwhelming.

389
00:25:29,750 --> 00:25:34,770
But if you will try to compare this cold with this cold, it is very similar.

390
00:25:34,790 --> 00:25:38,150
OK, so I hope you have understood this cold.

391
00:25:38,660 --> 00:25:43,400
So if you don't know this cold, OK, so if you are not able to understand this cold, no problem,

392
00:25:43,400 --> 00:25:43,640
OK?

393
00:25:43,670 --> 00:25:45,290
So this cold is really good.

394
00:25:45,470 --> 00:25:48,030
OK, this cold will pass all your discusses.

395
00:25:48,080 --> 00:25:52,580
This cold is really good, but if we want to optimise then this is the way to optimise.

396
00:25:52,760 --> 00:25:55,400
OK, you will see this approach in many, many questions.

397
00:25:55,400 --> 00:25:57,560
OK, this is appointer approach.

398
00:25:58,100 --> 00:25:59,950
You will see this approach in many questions.

399
00:25:59,960 --> 00:26:02,840
So if you have any doubt in discussion, then please ask.

400
00:26:02,910 --> 00:26:07,700
OK, and my suggestion will be please take an example and run this cold.

401
00:26:07,880 --> 00:26:10,460
OK, take the example of Mississippi.

402
00:26:10,770 --> 00:26:16,010
OK, so here I have discussed the example of Mississippi, so take the example of Mississippi and try

403
00:26:16,010 --> 00:26:20,960
to rent this good OK standpoint simulating in plastic.

404
00:26:22,340 --> 00:26:25,670
OK, so this cold is very, very good.

405
00:26:26,120 --> 00:26:28,070
So what is the time and the space complexity.

406
00:26:28,070 --> 00:26:33,650
So the time complexity is when and the space complexities even.

407
00:26:35,540 --> 00:26:38,300
OK, so I will share the call with you.

408
00:26:38,750 --> 00:26:39,230
Thank you.

