1
00:00:01,760 --> 00:00:02,390
Hi everyone.

2
00:00:02,390 --> 00:00:07,640
So in this video we are going to solve this question print all the prefixes of a given string.

3
00:00:07,640 --> 00:00:13,500
So this is the input string and we have to print all the prefix of the given string.

4
00:00:13,520 --> 00:00:16,590
So for example in this case our output should be.

5
00:00:16,610 --> 00:00:18,050
So the first prefix is a.

6
00:00:18,110 --> 00:00:22,310
Then a B then ABC then ABC.

7
00:00:22,310 --> 00:00:29,210
So these are all the prefixes and we have to print all these prefixes.

8
00:00:29,210 --> 00:00:30,650
So how can we do that.

9
00:00:30,650 --> 00:00:36,090
So it is very obvious solution just simple implementation problem.

10
00:00:36,110 --> 00:00:39,230
So this is your input string and what are you going to do.

11
00:00:39,230 --> 00:00:43,020
So this is there not index zero index 1 2 and 3.

12
00:00:43,280 --> 00:00:47,250
And similarly for so first you have to print a.

13
00:00:47,260 --> 00:00:49,450
So that means you have to print from index to zero.

14
00:00:49,480 --> 00:00:55,960
So what is a A's start printing from index zero 0 and Brent Bill index zero that means only one character

15
00:00:56,410 --> 00:00:57,500
for a b what I'm doing.

16
00:00:57,500 --> 00:00:59,010
Start printing from index zero.

17
00:00:59,020 --> 00:01:02,230
And Brent build index 1 including index 1.

18
00:01:02,410 --> 00:01:04,580
Similarly for printing ABC what I'm doing.

19
00:01:04,600 --> 00:01:06,420
Start printing from index zero.

20
00:01:06,550 --> 00:01:13,260
And you have to print Bill index to so and including index to avoid printing a B.

21
00:01:13,350 --> 00:01:17,010
So ABC this will be ABC.

22
00:01:17,210 --> 00:01:18,470
So what printing obesity.

23
00:01:18,500 --> 00:01:20,150
Start printing from index zero.

24
00:01:20,180 --> 00:01:24,640
And you have to print build index 3 and obviously including index 3.

25
00:01:24,650 --> 00:01:30,100
So just you have to do this small amount of work and if you notice the starting point.

26
00:01:30,200 --> 00:01:37,480
So can I say this is the starting point the starting index and I can say this is the ending index.

27
00:01:37,660 --> 00:01:41,370
So this is the starting index which is constant 0 0 0 0.

28
00:01:41,530 --> 00:01:45,450
And this is the ending index which is going to be already able.

29
00:01:45,670 --> 00:01:47,400
So how can this all this caution.

30
00:01:47,410 --> 00:01:50,650
Again I told you just this is just implementation volume.

31
00:01:50,650 --> 00:01:53,110
There is no logic in this question.

32
00:01:53,230 --> 00:01:55,310
You just have to write the code.

33
00:01:55,420 --> 00:01:56,690
So what do you do.

34
00:01:56,710 --> 00:02:00,410
This is a beauty you will take a variable.

35
00:02:00,420 --> 00:02:01,470
And so this is.

36
00:02:01,470 --> 00:02:04,550
And so what Andrew Louis does start from zero.

37
00:02:04,550 --> 00:02:06,810
And we go to three.

38
00:02:06,920 --> 00:02:10,960
So when and is that dissipation what do we do you will start.

39
00:02:11,060 --> 00:02:15,070
So either start will become I will start for this start from zero always.

40
00:02:15,110 --> 00:02:21,920
So what I will do I will start printing from index to zero so I will need a for loop so this loop will

41
00:02:21,920 --> 00:02:23,980
start printing from index 0.

42
00:02:24,160 --> 00:02:34,220
And index simple so you need to loop so when loop is actually loop for and index.

43
00:02:34,560 --> 00:02:36,310
And the second is in that most loop.

44
00:02:36,330 --> 00:02:43,540
So this loop will start from these stodgy nicks and it will go Delta and index simple.

45
00:02:43,590 --> 00:02:50,240
So let us write the code and you guys can understand it better that we so let me remove everything from

46
00:02:50,250 --> 00:02:53,940
here.

47
00:02:54,110 --> 00:03:01,110
Don't worry I will give you the code probably.

48
00:03:01,130 --> 00:03:06,500
So what we are going to do let us create the function that the function is going to be void because

49
00:03:06,620 --> 00:03:07,720
we only have to print.

50
00:03:07,730 --> 00:03:09,830
We don't have to do anything else.

51
00:03:10,160 --> 00:03:13,520
So the name of the function is print all prefixes

52
00:03:16,070 --> 00:03:24,310
so what we should do what it will take as input and it will take a character as input let's call it

53
00:03:24,400 --> 00:03:25,400
string.

54
00:03:25,510 --> 00:03:33,780
So I'm digging a string as input so I need doing almost to loop first is the outer loop I'm calling

55
00:03:33,780 --> 00:03:34,030
it.

56
00:03:34,050 --> 00:03:38,370
And so and we'll start from zero.

57
00:03:38,410 --> 00:03:44,920
You can write like this and this SDR alien of SD odd.

58
00:03:44,960 --> 00:03:46,430
So this is the first option.

59
00:03:46,520 --> 00:03:54,080
The second option to write is you can write like this string off end is not close to the null character

60
00:03:55,320 --> 00:03:58,880
more tired of it than you will do and plus plus.

61
00:03:58,880 --> 00:04:09,060
So my End Point is our trading and now I need a pointer so my start point it will start from zero and

62
00:04:09,060 --> 00:04:13,020
the start will go till end start listless.

63
00:04:13,230 --> 00:04:17,970
I will print so see out s.t. out of start

64
00:04:20,760 --> 00:04:29,230
simple and head I will write C out and lean and now let us call this function.

65
00:04:29,300 --> 00:04:34,570
So first let us create a string so string SDR.

66
00:04:35,660 --> 00:04:43,240
So let's say the string is a b c d and now it's time to call the function and best Delta program.

67
00:04:43,240 --> 00:04:51,920
So the name let's copy the name print all prefix i will give the string as input and I think of a code

68
00:04:51,920 --> 00:04:52,660
should work fine.

69
00:04:53,540 --> 00:04:54,950
So let us test our code

70
00:04:59,750 --> 00:05:06,920
and these are all the prefixes a a b ABC and a b c.

71
00:05:07,160 --> 00:05:10,100
So now let's try to understand how the code is working.

72
00:05:15,110 --> 00:05:17,980
So as discussed efficiency I knew to loop.

73
00:05:17,990 --> 00:05:19,770
So this is the end.

74
00:05:20,030 --> 00:05:21,100
And this is the start.

75
00:05:21,110 --> 00:05:29,350
So and we'll move in this direction and you will start printing from index 0 in the end index so just

76
00:05:29,370 --> 00:05:30,190
simple when the.

77
00:05:30,310 --> 00:05:32,590
So let's get started.

78
00:05:32,590 --> 00:05:33,710
So what I'm doing.

79
00:05:33,880 --> 00:05:41,550
This is an index so this is index and so this is index n.

80
00:05:41,580 --> 00:05:44,160
So initially the value of index and is 0.

81
00:05:44,160 --> 00:05:46,010
It is starting from 0.

82
00:05:46,110 --> 00:05:49,070
I haven't nicked it start so index start is initially zero.

83
00:05:49,080 --> 00:05:51,300
Check this condition and start this list in articles to end.

84
00:05:51,320 --> 00:05:57,770
Yes print the correct bet so I will print correctly now start will become 1.

85
00:05:57,770 --> 00:06:01,560
So this condition will become false if this condition to become false.

86
00:06:01,760 --> 00:06:02,950
Go to the next line.

87
00:06:03,080 --> 00:06:04,720
So I will go to the next line.

88
00:06:04,760 --> 00:06:09,050
Now the value of fandom will become one because we have written and a plus plus.

89
00:06:09,050 --> 00:06:11,230
Then you start will again start from zero.

90
00:06:11,240 --> 00:06:13,910
You will print e then it will become one.

91
00:06:13,940 --> 00:06:18,350
So you will print B then it will become do so as soon as it becomes 2.

92
00:06:18,890 --> 00:06:23,940
So this condition will again become false and it will go to the next line C out and line.

93
00:06:24,050 --> 00:06:29,840
Similarly the value of an index will become two because this is and plus plus the value of start will

94
00:06:29,840 --> 00:06:34,220
become zero you will print a the values type will become one you will print to be the values that will

95
00:06:34,220 --> 00:06:39,670
become two you will see the value of start will become three and you will stop because this condition

96
00:06:39,670 --> 00:06:45,890
will become false then you will go to the next line again the end index will become three because you

97
00:06:45,890 --> 00:06:49,640
have written and plus so the start will start from zero.

98
00:06:49,640 --> 00:06:53,090
You will bring to E and it will become one you will bring to B.

99
00:06:53,160 --> 00:06:59,090
It will become too you will print c it will become 3 you will bank D then it will become fold.

100
00:06:59,270 --> 00:07:02,360
So 4 is good then 3 and you will stop.

101
00:07:02,360 --> 00:07:05,120
So this condition will become voice and you will stop.

102
00:07:05,120 --> 00:07:07,880
Then you will give C outline lane so you will go to the next line.

103
00:07:07,940 --> 00:07:13,780
So that's why there is a line here that's why there is a line coming out here.

104
00:07:13,780 --> 00:07:22,800
So then the value of and will become 4 and at Fort index you can check it will become equal to the characters

105
00:07:22,800 --> 00:07:24,760
or the string is ABC.

106
00:07:25,230 --> 00:07:32,040
You can see the string is actually ABC and at index forward so this is indexed would add to next world.

107
00:07:32,070 --> 00:07:40,680
My electric base did so if the value of and is for this condition will become false and basically you

108
00:07:40,680 --> 00:07:46,170
will come out of the for loop and basically my function the vocal function is a what.

109
00:07:46,170 --> 00:07:50,970
And this is my output so that's how this code is working.

110
00:07:52,770 --> 00:07:55,190
So I hope you guys can understand this code.

111
00:07:55,200 --> 00:08:00,030
So if you have any doubt and discussion you can definitely ask me and one modification of this question

112
00:08:00,030 --> 00:08:00,730
can be.

113
00:08:00,780 --> 00:08:05,760
So what we are doing we are printing all the prefixes we have printing all the prefix.

114
00:08:05,760 --> 00:08:10,030
So the homework for you guys can be read you can do you can print all that suffix.

115
00:08:10,050 --> 00:08:13,470
So for example the input is a beauty.

116
00:08:13,710 --> 00:08:15,170
So what will be all the suffix.

117
00:08:15,180 --> 00:08:16,510
So it will be B.

118
00:08:16,650 --> 00:08:23,670
Then it will be CDE then it will be writing b c and then it will be ABC.

119
00:08:23,760 --> 00:08:26,420
So I hope you guys can do this.

120
00:08:26,430 --> 00:08:31,730
So we are printing all the suffix head print all suffix

121
00:08:35,190 --> 00:08:39,480
so again first you have to print this character then you have to print these two characters then you

122
00:08:39,480 --> 00:08:44,820
have to print these three characters and then you have to print these four characters and print all

123
00:08:44,820 --> 00:08:45,440
prefixes.

124
00:08:45,450 --> 00:08:46,460
What you are doing.

125
00:08:46,560 --> 00:08:52,530
If these string is ABC first you are printing this character then we were printing this then you are

126
00:08:52,530 --> 00:08:57,690
printing this and then we were printing this so the logic is going to be seen.

127
00:08:57,750 --> 00:09:02,730
Again I am telling you this is just the implementation problem if you ever try and write.

128
00:09:02,850 --> 00:09:08,400
If we tried to write the code for this problem according skills we will improve a lot to according skills

129
00:09:08,430 --> 00:09:11,100
will improve a lot.

130
00:09:11,100 --> 00:09:16,500
Again if you have any doubt in this question being double prefix are you encountered no doubt in this

131
00:09:16,510 --> 00:09:18,210
quotient and also fix.

132
00:09:18,270 --> 00:09:22,870
You can definitely offscreen that Q and A section so I will see you in the next video.

133
00:09:22,880 --> 00:09:23,340
Bye bye.
