1
00:00:01,400 --> 00:00:02,060
Hallowed event.

2
00:00:02,070 --> 00:00:06,640
So in this video we are going to decide one question reverse a string.

3
00:00:06,810 --> 00:00:17,230
So for example if the input is Hallowell so hello then space and then word so after reversing the string

4
00:00:18,080 --> 00:00:26,860
where do the reverse of this thing so D and R O W then space O N and E H.

5
00:00:26,920 --> 00:00:31,570
So far finding out that it was just start the string from the back.

6
00:00:31,570 --> 00:00:39,020
So be an odd or w the N or W then space so space then o an edge.

7
00:00:39,100 --> 00:00:41,020
So O double l e edge.

8
00:00:41,560 --> 00:00:44,490
So what do you have to do so given input string.

9
00:00:44,490 --> 00:00:50,730
Give it a posting and you have to convert the input string and doing that he was of the string so that

10
00:00:50,740 --> 00:00:51,840
is the meaning of the ocean.

11
00:00:51,870 --> 00:00:53,920
Reverse the string.

12
00:00:53,950 --> 00:00:55,290
Now let's take one more example.

13
00:00:55,300 --> 00:00:59,110
So suppose the input string is ABC.

14
00:00:59,410 --> 00:01:05,240
ABC then what you have to do so you will convert then would sing to which city votes so it reverses

15
00:01:05,320 --> 00:01:07,850
D C B and A.

16
00:01:08,080 --> 00:01:10,610
So I hope you understood the question.

17
00:01:10,900 --> 00:01:12,290
So now let's take one.

18
00:01:12,430 --> 00:01:21,250
One more example so suppose the input string is a b c b e f so how does this string will be stored inside

19
00:01:21,250 --> 00:01:22,790
the correct baddy.

20
00:01:22,870 --> 00:01:31,050
It does very with a then B then C then D then E then F and add then obviously you will have the null

21
00:01:31,060 --> 00:01:33,300
corrected.

22
00:01:33,520 --> 00:01:38,730
Now how you can dig the reverse of the string so the procedure is going to be very very simple.

23
00:01:41,200 --> 00:01:45,050
It is very obvious that you do not have to do anything with the null correct and incorrect is going

24
00:01:45,050 --> 00:01:46,940
to be present at the last position.

25
00:01:46,970 --> 00:01:49,410
So that is very obvious.

26
00:01:49,640 --> 00:01:51,250
Now what does that a lot of the string.

27
00:01:51,260 --> 00:01:57,970
So this is f then I F E so B C B and A.

28
00:01:58,000 --> 00:02:03,000
So this is the output and not let us discuss where this what should be our approach.

29
00:02:03,010 --> 00:02:07,890
So what I will do to obtain that it was the procedure is very simple.

30
00:02:08,000 --> 00:02:10,510
So the first and the last correct.

31
00:02:11,050 --> 00:02:13,990
So F will come here even come here.

32
00:02:14,050 --> 00:02:18,790
Now step the second and the last second will get better.

33
00:02:18,810 --> 00:02:25,900
So even come here and be welcome here and similarly Gib doing this so C and D will get SAB.

34
00:02:25,950 --> 00:02:34,810
So Deven go there and C will go mad and you can match so this is FCB CBE f EDI CB.

35
00:02:34,910 --> 00:02:38,270
So that is the approach that we are going to follow.

36
00:02:38,270 --> 00:02:39,290
So what is the approach.

37
00:02:39,320 --> 00:02:41,110
The approach is going to be very very simple.

38
00:02:41,120 --> 00:02:42,420
I will take two point.

39
00:02:42,890 --> 00:02:44,580
So this is my start point.

40
00:02:45,170 --> 00:02:48,220
This is my end point to what I will do.

41
00:02:48,230 --> 00:02:52,760
I will swap my start point with the end appointed.

42
00:02:52,850 --> 00:02:57,300
So start point I will move in this direction and point that it will move in this direction.

43
00:02:57,470 --> 00:03:01,720
So I will loose start plus plus I will do and minus minus.

44
00:03:02,030 --> 00:03:04,000
And we have to keep doing this.

45
00:03:04,040 --> 00:03:13,740
How many times so vital the start point does less than and point the you will have to perform these

46
00:03:13,800 --> 00:03:16,780
steps simple.

47
00:03:16,920 --> 00:03:19,560
So what do we lose so this start point.

48
00:03:19,590 --> 00:03:24,390
So E is going to subdivide the F so F will come here and even come here.

49
00:03:24,390 --> 00:03:26,940
Then you will loose start plus MSO start will come here.

50
00:03:27,330 --> 00:03:30,790
So this is my new start and this is my new end.

51
00:03:30,910 --> 00:03:34,630
So be and even get swept so you will lose start.

52
00:03:34,630 --> 00:03:37,160
Plus plus you will do and minus minus.

53
00:03:37,260 --> 00:03:38,450
So this is my new start.

54
00:03:38,490 --> 00:03:43,470
This is my new end so you will swap CND then you will do start plus plus.

55
00:03:43,470 --> 00:03:46,980
So this will become start and you will do it minus minus.

56
00:03:47,010 --> 00:03:53,430
So this will become and and now the condition will become void because now the start becomes good then

57
00:03:53,430 --> 00:03:53,820
end.

58
00:03:53,850 --> 00:04:03,510
So at this condition you will stop very very simple logic so if you want I can take one more example.

59
00:04:03,510 --> 00:04:04,850
For example ABC.

60
00:04:05,380 --> 00:04:12,000
So what I can do this is my start point but this is my and appointed swept starting in.

61
00:04:12,030 --> 00:04:17,260
So after the sweeping these are going to come here and is going to come here.

62
00:04:17,260 --> 00:04:19,720
Now start plus plus and minus minus.

63
00:04:20,230 --> 00:04:21,640
So this is your new start.

64
00:04:21,670 --> 00:04:27,710
This is your new end and demoed this or in again we will do this mapping.

65
00:04:27,770 --> 00:04:35,440
So after this wrapping B and C will get swept so C will come here and B will come here and again you

66
00:04:35,440 --> 00:04:37,350
will update to a start and end.

67
00:04:37,380 --> 00:04:40,140
So start plus plus and minus minus.

68
00:04:40,300 --> 00:04:43,890
So this will become your start and this will become your end.

69
00:04:44,050 --> 00:04:46,300
And at this point you will stop.

70
00:04:46,300 --> 00:04:52,190
So we have to do the work vital My start is less than and very very simple.

71
00:04:52,270 --> 00:04:55,930
So let us write the code and then we will write a have a called

72
00:04:59,570 --> 00:05:04,010
So where do letter turn type so I will not written anything I will just do that in just inside of my

73
00:05:04,010 --> 00:05:05,280
creek bed and only.

74
00:05:05,570 --> 00:05:11,330
And let's say the name of the function is reverse what it will take it will take a character that is

75
00:05:11,330 --> 00:05:16,630
input and what we have to do I have to take two pointers.

76
00:05:16,650 --> 00:05:18,390
So I have take the first pointer.

77
00:05:18,410 --> 00:05:21,170
So first point let us take that test name it start.

78
00:05:21,600 --> 00:05:26,790
So start the loop as it Zito and we loop as it did last year index.

79
00:05:26,870 --> 00:05:33,290
And in order to find out the last 16 I can use the function and so I would call the function Lent.

80
00:05:33,410 --> 00:05:39,370
I will give input as I have given poor daddy minus one.

81
00:05:39,440 --> 00:05:42,050
So this would be good and index.

82
00:05:42,080 --> 00:05:45,590
So let me check.

83
00:05:45,670 --> 00:05:47,710
So this is index 0.

84
00:05:47,710 --> 00:05:51,040
1 2 3 4 and 5.

85
00:05:51,130 --> 00:05:54,900
So it is very obvious that initially my start will be zero.

86
00:05:54,940 --> 00:05:57,290
It is very obvious I want to find out.

87
00:05:57,310 --> 00:06:00,340
And so if you will apply the lend function.

88
00:06:00,340 --> 00:06:04,980
So what is the lent lent us 1 2 3 4 5 and 6.

89
00:06:04,990 --> 00:06:11,350
So Lent is actually 6 and the index of 5 and then takes off and is actually 5.

90
00:06:11,380 --> 00:06:19,600
So that means the index is actually lent minus 1 the index is actually lent to minus 1.

91
00:06:19,640 --> 00:06:24,210
You can consider the above example also so in this example.

92
00:06:24,380 --> 00:06:26,170
This was my start.

93
00:06:26,240 --> 00:06:33,010
So we do not have any confusion I would start start will be initially zero very obvious what is the

94
00:06:33,050 --> 00:06:39,890
Lent so Lent is actually filled and this is my end so end is actually.

95
00:06:39,890 --> 00:06:43,380
So this is index 0 and X1 and X2 in our next 3.

96
00:06:43,400 --> 00:06:52,330
So I can see that my end is actually lent minus 1 I can see my end is actually the Lent minus 1.

97
00:06:52,400 --> 00:06:59,660
So I'm using the Lent function so we have all read and the code for the Lent function in our previous

98
00:06:59,660 --> 00:07:07,160
lessons and then what we have to do we have to do swapping and the condition is very simple VI start

99
00:07:07,280 --> 00:07:12,860
is list and end you will loose wrapping so I have and will function step in C++.

100
00:07:13,790 --> 00:07:17,090
So I want to sep start and end so Sep start

101
00:07:19,700 --> 00:07:25,520
and end so I'm swapping and didn't start plus plus and minus minus.

102
00:07:25,560 --> 00:07:30,920
Very very simple and the return type of the function is wide so we do not have to do anything and here

103
00:07:30,970 --> 00:07:32,340
what we would what we will do.

104
00:07:32,340 --> 00:07:35,280
I will call the function so see out

105
00:07:38,180 --> 00:07:41,450
so Firstly let us call the function to the name of the function is reverse

106
00:07:44,750 --> 00:07:47,180
then add the function is it was I am passing and put

107
00:07:50,760 --> 00:07:57,870
and after passing the input let s spent reversed.

108
00:07:57,900 --> 00:08:01,140
String order can't be reversed.

109
00:08:01,150 --> 00:08:03,330
Correct Daddy name.

110
00:08:05,120 --> 00:08:09,950
And we know that the daddy are past biodefense.

111
00:08:09,950 --> 00:08:15,230
So whatever you are doing changes with the correct in dysfunction function it will get reflected in

112
00:08:15,230 --> 00:08:16,460
Maine also.

113
00:08:16,550 --> 00:08:17,620
I'm repeating myself.

114
00:08:17,690 --> 00:08:22,850
We know that the ads are passed by at a friend's soon so passed by the office.

115
00:08:22,850 --> 00:08:29,090
So whatever changes you are doing with the ad inside the reverse function it is going to be reflected

116
00:08:29,090 --> 00:08:29,660
inside.

117
00:08:29,750 --> 00:08:33,110
Also so no let us based our program

118
00:08:37,200 --> 00:08:37,890
so.

119
00:08:38,010 --> 00:08:38,310
Okay.

120
00:08:38,310 --> 00:08:40,870
So what is happening here at this planet will say the.

121
00:08:40,890 --> 00:08:46,440
I do not know what is lent because Lent is defined below the reverse function so that this line compiler

122
00:08:46,440 --> 00:08:48,330
doesn't know what is lent.

123
00:08:48,330 --> 00:08:50,700
So what we have to do is just copy.

124
00:08:50,700 --> 00:08:53,340
Sorry just just cut and paste above.

125
00:08:54,300 --> 00:08:57,270
So we have to write the code of the land above.

126
00:08:57,270 --> 00:09:03,030
I'm repeating myself this at this link compiler doesn't know what this Lent function because the Lent

127
00:09:03,030 --> 00:09:07,120
function was written after the release function after this line.

128
00:09:07,230 --> 00:09:10,230
So that's why it will give you error that it doesn't know what is lent.

129
00:09:10,260 --> 00:09:17,980
So you have to write lend function before and obviously let us change this one also.

130
00:09:18,130 --> 00:09:21,650
So it seemed a the guideline name and a hundred.

131
00:09:21,670 --> 00:09:24,490
So that means I can let me start delimiter by default.

132
00:09:24,490 --> 00:09:29,880
This new line now let us test our program

133
00:09:34,820 --> 00:09:36,960
so this is reverse.

134
00:09:37,030 --> 00:09:44,500
Okay so the name of the ad is actually name the name of the ad is actually name.

135
00:09:44,600 --> 00:09:54,900
I want to reverse ABC so your string is ABC and the reverse a string is CB.

136
00:09:54,920 --> 00:10:03,950
Now let us give a b c v e f so your string is a b c d e f and after that it was in it will become F

137
00:10:03,960 --> 00:10:07,120
E D CBE.

138
00:10:07,140 --> 00:10:10,890
Now let us test one more time so this time it does give.

139
00:10:10,890 --> 00:10:11,430
Hello world.

140
00:10:11,580 --> 00:10:15,290
So hello space world.

141
00:10:16,280 --> 00:10:22,970
So this is your input string Hello World and this is you reverse the string DL out of the blue space

142
00:10:23,100 --> 00:10:30,010
0 and then each you can give multiple spaces also saying don't get land can handle multiple spaces also

143
00:10:30,020 --> 00:10:37,150
for example hello then space space space and then word.

144
00:10:37,280 --> 00:10:44,480
So this is your input string and after the reversing after the reverse function this is yet output string.

145
00:10:44,480 --> 00:10:44,960
This is your.

146
00:10:44,980 --> 00:10:52,410
It was this string so other it was function called is looking perfectly fine and the logic is very simple

147
00:10:52,440 --> 00:10:59,870
take two pointer one at the beginning one at the end keep slapping them start will move in default word

148
00:10:59,870 --> 00:11:05,340
not action and pointer will move in the backward direction and you have to keep doing this work while

149
00:11:05,430 --> 00:11:09,490
you start is actually list and end very very simple.

150
00:11:09,570 --> 00:11:13,430
So if you have any doubt in discussion you can definitely ask me I will do the next one.

151
00:11:13,440 --> 00:11:13,770
Bye bye.
