1
00:00:02,340 --> 00:00:03,060
Hi, everyone.

2
00:00:03,090 --> 00:00:06,280
So today we are going to solve this problem, reverse string.

3
00:00:06,870 --> 00:00:09,780
OK, so the input will be basically a string.

4
00:00:10,140 --> 00:00:11,220
So the input is a string.

5
00:00:11,220 --> 00:00:14,490
And what we have to do, we have to reverse that string, OK?

6
00:00:14,790 --> 00:00:20,690
So after reversing this string so our output will become all an edge.

7
00:00:20,780 --> 00:00:26,820
OK, and similarly, if the input is this after reversing the string, the output will be only, the

8
00:00:26,820 --> 00:00:33,320
output will be only and then bursting is broke, then output will be so be at 60.

9
00:00:33,690 --> 00:00:37,240
OK, so basically we have to reverse the given string.

10
00:00:38,040 --> 00:00:39,970
Now how we can solve this question.

11
00:00:40,260 --> 00:00:41,980
So basically the first way.

12
00:00:42,450 --> 00:00:44,390
So there are two ways to solve this question.

13
00:00:44,730 --> 00:00:47,960
So the first way to solve this question is with the help of a string.

14
00:00:48,310 --> 00:00:52,170
OK, so the first way is basically with the help of a stack.

15
00:00:53,240 --> 00:00:54,890
Now alerted the input is hello.

16
00:00:55,820 --> 00:01:00,410
So if the input is hello, so what we will do, so I will create a strike.

17
00:01:01,970 --> 00:01:04,250
Stack of it will be a stack of characters.

18
00:01:04,319 --> 00:01:07,730
OK, so I will have a stack of characters.

19
00:01:09,280 --> 00:01:14,560
Now, what I'm going to do is so I would like to the string, so I am standing at what I will do, I

20
00:01:14,560 --> 00:01:22,210
will push h e push inside the stick and or so push l l oh.

21
00:01:22,360 --> 00:01:27,880
And finally the string will be over and this will be out and this will be the condition of the stick.

22
00:01:27,940 --> 00:01:31,240
OK, so what I am doing, I am pushing every character.

23
00:01:32,360 --> 00:01:36,710
So I am pushing every character of the string into the Hashmat into this deck.

24
00:01:36,740 --> 00:01:40,190
OK, so Bush, every character in Lustick.

25
00:01:42,650 --> 00:01:46,020
Now, what I'm going to do is I will pop every character.

26
00:01:46,070 --> 00:01:47,600
So this was the first step.

27
00:01:47,630 --> 00:01:51,260
Now the second step will be pop every character.

28
00:01:53,820 --> 00:01:55,320
And that will be our answer.

29
00:01:55,740 --> 00:01:58,440
OK, so Bob, so Popol.

30
00:01:59,840 --> 00:02:04,250
Then l so and then L then E!

31
00:02:05,370 --> 00:02:06,120
Then EJ.

32
00:02:07,000 --> 00:02:12,970
OK, so the state will become empty, Stagg will become empty, and this is my reversed string.

33
00:02:13,000 --> 00:02:15,070
OK, so this is my.

34
00:02:16,170 --> 00:02:17,370
Reversed string.

35
00:02:18,730 --> 00:02:20,050
So this was very simple.

36
00:02:20,360 --> 00:02:26,620
OK, you can take one more example, also, suppose the string is very simple, Stinger's, you only

37
00:02:26,920 --> 00:02:33,670
then what will happen initialised equilibrium between now let's say I did so a push a and then the string

38
00:02:33,670 --> 00:02:34,480
becomes empty.

39
00:02:34,490 --> 00:02:36,790
So after pushing I have to pop the character.

40
00:02:36,800 --> 00:02:40,070
So after popping my output will be OK.

41
00:02:40,450 --> 00:02:41,740
So this is very simple.

42
00:02:41,770 --> 00:02:44,060
Now what will be the time and the space complexity.

43
00:02:44,350 --> 00:02:48,970
So basically the time complexity is just we are taking over the string so it will be linear and the

44
00:02:48,970 --> 00:02:53,260
space complexity is basically own because we will be creating a strike.

45
00:02:54,180 --> 00:02:58,180
OK, so we are creating a strike and is basically the length of the string.

46
00:02:58,600 --> 00:03:01,210
OK, and it's basically the length of the string.

47
00:03:02,310 --> 00:03:04,500
So now let us write the code, OK?

48
00:03:07,800 --> 00:03:09,210
So what do you have to do?

49
00:03:09,390 --> 00:03:12,810
I have to create a stack of characters.

50
00:03:13,230 --> 00:03:15,770
OK, so this problem is basically present.

51
00:03:15,780 --> 00:03:16,440
Don't get caught.

52
00:03:16,540 --> 00:03:20,110
OK, so you can see this is the same problem that we have discussed.

53
00:03:20,640 --> 00:03:22,530
So what I'm doing here is.

54
00:03:23,950 --> 00:03:30,190
I am creating a stack of characters and let's see the name of stackers ASG, so what I'm going to do

55
00:03:30,190 --> 00:03:31,930
here, I have to write it over the string.

56
00:03:32,650 --> 00:03:34,350
OK, so let's do it.

57
00:03:34,360 --> 00:03:36,220
So I equals zero.

58
00:03:37,530 --> 00:03:39,390
I listed as Nazis.

59
00:03:43,850 --> 00:03:47,640
And libelous place, so I have to push every crack inside this tick.

60
00:03:47,670 --> 00:03:51,890
OK, so what I'm doing here is push every character.

61
00:03:53,810 --> 00:03:57,440
Decided to stick, so this was the first step, OK, that we have discussed.

62
00:03:58,370 --> 00:04:02,750
So s-t, don't push, so let's change the name.

63
00:04:04,440 --> 00:04:11,910
So I'm changing the name to be OK, so I consider a list the neo-Nazis so stagnant Bush aof I.

64
00:04:13,720 --> 00:04:17,310
OK, so after the first step, now what we have to do.

65
00:04:17,610 --> 00:04:19,200
So this is the second step.

66
00:04:19,200 --> 00:04:21,519
We have to pop every character.

67
00:04:21,579 --> 00:04:21,899
OK.

68
00:04:23,560 --> 00:04:25,090
So I have to pop every character.

69
00:04:28,740 --> 00:04:32,110
So let us trade so forward and DayQuil zero.

70
00:04:32,130 --> 00:04:36,320
So how many correctible represented inside the state that will be incorrect.

71
00:04:36,570 --> 00:04:38,640
And is basically the size of the vector.

72
00:04:38,700 --> 00:04:42,420
OK, so I call zero I and Lot says.

73
00:04:44,270 --> 00:04:45,170
I placeless.

74
00:04:47,090 --> 00:04:51,290
So AFIC is basically stacked that top.

75
00:04:53,150 --> 00:04:55,130
And then staggered artpop.

76
00:04:57,110 --> 00:05:01,400
OK, and that's all so you can see here.

77
00:05:03,800 --> 00:05:08,810
So basically, the return of the function is void, so they don't have to return anything and basically

78
00:05:08,810 --> 00:05:12,980
what we have to do so you can see it is passed by reference.

79
00:05:13,160 --> 00:05:15,740
OK, so the given vector is passed by reference.

80
00:05:15,990 --> 00:05:19,280
That means we have changes inside the factory.

81
00:05:19,310 --> 00:05:22,480
OK, so we have to rule changes inside the factory.

82
00:05:22,550 --> 00:05:24,150
We have to modify the factory.

83
00:05:25,460 --> 00:05:28,040
OK, so I'm here modifying the factory.

84
00:05:28,040 --> 00:05:33,520
You can see here I am modifying Alphie is basically a startup and stagnant Bob.

85
00:05:33,770 --> 00:05:35,630
So I had this line line number 15.

86
00:05:36,640 --> 00:05:39,220
So at this lendee, that bell is reversed.

87
00:05:39,250 --> 00:05:45,730
OK, so basically let us again, so if you want, you can, Driton, for example, of the string, let's

88
00:05:45,730 --> 00:05:47,850
say each each.

89
00:05:48,250 --> 00:05:49,830
So this is passed by defense.

90
00:05:49,990 --> 00:05:52,150
So inside the stack.

91
00:05:52,160 --> 00:05:54,270
So the first loop, Bush, every character.

92
00:05:54,520 --> 00:05:56,910
So each e each.

93
00:05:56,980 --> 00:05:59,070
Now the second step up, every character.

94
00:05:59,080 --> 00:06:05,280
So Pop Edge, Bob and Bob, each one, for example, the ABC.

95
00:06:05,920 --> 00:06:15,000
So this is initially stake is empty then Bush A, Bush B, Bush C then what I'm doing here is Popsie

96
00:06:15,280 --> 00:06:19,270
put it here, probably put it here popi put it here.

97
00:06:19,270 --> 00:06:20,260
And this is my answer.

98
00:06:20,260 --> 00:06:22,950
c.B, we do not have to return anything okay.

99
00:06:22,960 --> 00:06:24,100
We just have to change.

100
00:06:24,700 --> 00:06:26,840
We just have to modify the given vector.

101
00:06:26,930 --> 00:06:27,280
OK.

102
00:06:29,380 --> 00:06:32,230
So now let us try to submit our gold.

103
00:06:34,700 --> 00:06:36,610
OK, so our goal is working fine.

104
00:06:37,170 --> 00:06:38,760
Now let's see the question again.

105
00:06:39,050 --> 00:06:43,670
So the question is, is it we have to do using it using over an extra memory?

106
00:06:43,700 --> 00:06:45,620
OK, so here we are using a stick.

107
00:06:45,620 --> 00:06:51,170
So basically we are using big off and memory and we have to use constant and constant extra memory.

108
00:06:51,200 --> 00:06:52,760
So how we can solve this question.

109
00:06:53,070 --> 00:06:54,530
OK, so let's see.

110
00:06:57,730 --> 00:07:00,070
So this is a very simple question, what you can do here is.

111
00:07:01,390 --> 00:07:03,650
We will solve this question with the help of 2.0.

112
00:07:03,850 --> 00:07:05,730
OK, so this is my input string.

113
00:07:07,240 --> 00:07:12,150
I will take two pointer, start pointer and pointer married.

114
00:07:12,190 --> 00:07:18,850
I'm going to do is swap start and end sep start pointer and pointer.

115
00:07:18,880 --> 00:07:21,880
So what will become so all will come here.

116
00:07:22,600 --> 00:07:27,600
It will come here then I will start plus plus and minus minus.

117
00:07:28,180 --> 00:07:29,680
So this is my new start.

118
00:07:30,190 --> 00:07:32,620
This is my new end again.

119
00:07:32,620 --> 00:07:34,540
I am going to start and end.

120
00:07:34,540 --> 00:07:41,410
So after stepping so this will become L, this will become E then start will come here.

121
00:07:42,320 --> 00:07:47,070
And will come here, then what I'm going to do is I will strap, start and end.

122
00:07:47,090 --> 00:07:51,830
So L will be swept with L and then start will come here.

123
00:07:53,140 --> 00:07:58,750
And will come here, so when start becomes great, then and I will stop.

124
00:08:00,860 --> 00:08:05,750
OK, so basically what we have to do, we have to step start and end point that only.

125
00:08:07,130 --> 00:08:08,720
So let's take one more example.

126
00:08:11,310 --> 00:08:15,430
So if the input is, let's say A, B, C, D.

127
00:08:16,300 --> 00:08:18,110
OK, so what should be my output?

128
00:08:18,330 --> 00:08:23,680
So the output should be the C, B, E, OK, so let's take two pointers.

129
00:08:23,970 --> 00:08:27,280
So this is my start point and this is my end pointer.

130
00:08:27,690 --> 00:08:29,040
SNAP, start and end.

131
00:08:29,400 --> 00:08:30,750
So they will come here.

132
00:08:31,850 --> 00:08:32,760
He will come here.

133
00:08:33,409 --> 00:08:37,179
OK, now start will start plus, plus and minus minus.

134
00:08:37,179 --> 00:08:40,400
So this is start, this is end, slap, start and end.

135
00:08:40,640 --> 00:08:45,540
So it will become C, it will become B, then start, will become good then.

136
00:08:45,560 --> 00:08:50,460
And so basically start will come here and will come here.

137
00:08:50,480 --> 00:08:52,880
So then start is good and we will stop.

138
00:08:54,380 --> 00:08:55,740
And this is my output.

139
00:08:55,880 --> 00:08:57,380
OK, you can compare.

140
00:08:57,380 --> 00:08:59,630
So our output is correct now.

141
00:08:59,720 --> 00:09:01,550
Little bit of time and the space complexity.

142
00:09:01,880 --> 00:09:03,650
So their time complexity will be linear.

143
00:09:03,830 --> 00:09:11,090
OK, so this operation, this is question time over time and we are not taking any extra space so the

144
00:09:11,090 --> 00:09:12,050
space will be open.

145
00:09:12,320 --> 00:09:13,010
OK, so.

146
00:09:13,990 --> 00:09:17,170
Time is linear and constant extra memory.

147
00:09:17,230 --> 00:09:18,700
OK, so let us write the code.

148
00:09:20,880 --> 00:09:22,890
So first, let us comment about this one.

149
00:09:27,100 --> 00:09:33,810
Now we have to do I have to take two point us start point, which is at the beginning and end point,

150
00:09:34,690 --> 00:09:36,820
which will be Iraq minus one.

151
00:09:37,820 --> 00:09:40,790
OK, because the indexing starts from zero.

152
00:09:42,180 --> 00:09:46,750
I would have to do so while start this list and articles to end.

153
00:09:48,900 --> 00:09:56,550
I will do stepping operation to slap aof start, so basically strap is in belt function inside C++.

154
00:09:56,580 --> 00:10:03,030
OK, so I am swapping start and end then what I have to do is start plus plus and minus minus.

155
00:10:04,570 --> 00:10:05,350
And that's all.

156
00:10:06,130 --> 00:10:08,350
OK, so let's try to submit.

157
00:10:11,480 --> 00:10:13,760
OK, so our goal is working fine.

158
00:10:13,830 --> 00:10:16,760
OK, now there is one inbuilt function also.

159
00:10:18,350 --> 00:10:20,870
There is one elaborate function, which is called reverse.

160
00:10:20,900 --> 00:10:27,370
OK, so we haven't built function reverse and I will pass it over to begin and end.

161
00:10:28,250 --> 00:10:35,660
So it was a not begin nod and OK, and our vector will be reversed.

162
00:10:35,720 --> 00:10:37,310
OK, so let's try to submit.

163
00:10:40,820 --> 00:10:46,560
OK, so our Gore is working fine, so this reverse function, this is inbuilt function inside the C++.

164
00:10:46,620 --> 00:10:48,720
OK, so it can reverse anything.

165
00:10:48,980 --> 00:10:50,570
So here it is, reversing better.

166
00:10:50,840 --> 00:10:55,940
Now, if you have a string, for example, if you have here string A, then also this reverse function

167
00:10:55,940 --> 00:10:56,420
will work.

168
00:10:56,450 --> 00:11:00,150
OK, so this inverse function is invoked C++ function.

169
00:11:01,220 --> 00:11:06,360
So finally the time and the space complexity time is linear and we are using constant extra space.

170
00:11:06,440 --> 00:11:06,770
OK.

171
00:11:07,130 --> 00:11:09,530
So if you have any doubt in this problem, please ask.

172
00:11:09,560 --> 00:11:10,460
OK, thank you.

