1
00:00:01,620 --> 00:00:02,230
Hello everyone.

2
00:00:02,220 --> 00:00:03,240
Welcome to this video.

3
00:00:03,240 --> 00:00:07,420
So in this session what we do we will solve one more problem with the help of occasion.

4
00:00:07,540 --> 00:00:10,160
OK so the name of the problem is count digits.

5
00:00:11,430 --> 00:00:13,560
Okay so what is the problem.

6
00:00:13,560 --> 00:00:14,760
The problem is very simple.

7
00:00:14,760 --> 00:00:21,090
Suppose you will be given a number let's say the number is 4 0 2 5 and you have to tell the number of

8
00:00:21,090 --> 00:00:23,770
digits in the numbers so number of digits is food.

9
00:00:23,790 --> 00:00:24,300
Okay.

10
00:00:24,300 --> 00:00:24,720
Somalia.

11
00:00:24,720 --> 00:00:26,070
The number is 125.

12
00:00:26,100 --> 00:00:27,660
Number of digits is three.

13
00:00:27,690 --> 00:00:30,840
If the number is 20 the number of digits is 2.

14
00:00:30,840 --> 00:00:31,260
Okay.

15
00:00:31,350 --> 00:00:34,680
So you have to count the number of digits present in the number.

16
00:00:34,980 --> 00:00:35,590
Okay.

17
00:00:35,670 --> 00:00:36,980
Now what I have to do.

18
00:00:36,980 --> 00:00:43,600
So I have to write the function count what it will take it will take a number as input and you have

19
00:00:43,600 --> 00:00:46,720
to tell how many digits are present in this number.

20
00:00:46,730 --> 00:00:49,180
And now there is a constraint on the value of.

21
00:00:49,360 --> 00:00:51,830
So the end will be good then articles 2 1.

22
00:00:51,850 --> 00:00:52,370
Okay.

23
00:00:52,450 --> 00:00:56,750
So the value of in the end what is then and will be a natural number.

24
00:00:56,770 --> 00:00:57,000
Okay.

25
00:00:57,010 --> 00:00:59,960
So this is our constraint and is a natural number.

26
00:00:59,980 --> 00:01:00,260
Okay.

27
00:01:00,270 --> 00:01:06,070
That means and cannot be zero and and basically cannot be left not of course to zero and will always

28
00:01:06,070 --> 00:01:07,360
be a positive number.

29
00:01:07,360 --> 00:01:07,920
Okay.

30
00:01:08,110 --> 00:01:09,420
So okay.

31
00:01:09,520 --> 00:01:14,950
So we have to calculate the number of digits present in item but now how going to calculate the number

32
00:01:14,950 --> 00:01:15,750
of digits.

33
00:01:15,760 --> 00:01:16,050
Okay.

34
00:01:16,060 --> 00:01:18,630
So what we will do we will take the help of recursion.

35
00:01:18,700 --> 00:01:19,240
Okay.

36
00:01:19,240 --> 00:01:23,890
If you remember we have already solved this problem with the help of four loop by little but here since

37
00:01:23,940 --> 00:01:26,650
we're using regression things we are learning recursion.

38
00:01:26,740 --> 00:01:29,400
So we will try to solve this problem with the help of recursion.

39
00:01:29,410 --> 00:01:32,240
Now how we can solve this problem with the help of the occasion.

40
00:01:32,260 --> 00:01:33,970
So what will happen.

41
00:01:34,000 --> 00:01:38,090
Okay so this is our number 4 0 2 5.

42
00:01:38,110 --> 00:01:43,740
So what I'm planning to do here is what I will do I will split this number okay.

43
00:01:43,760 --> 00:01:46,700
I will tell the recursion to solve this problem for me.

44
00:01:46,730 --> 00:01:48,940
So recursion what would load it occasion will turn me down.

45
00:01:48,940 --> 00:01:53,070
I said three and then 12 what I will do I will add plus 1.

46
00:01:53,560 --> 00:01:56,570
So output will be for okay.

47
00:01:56,700 --> 00:01:59,090
So what I will do I will break my number.

48
00:01:59,490 --> 00:02:01,610
And then I will tell regression.

49
00:02:01,650 --> 00:02:04,990
Then I will tell revision to solve this problem.

50
00:02:05,160 --> 00:02:07,770
So the question will give me tree and I will add plus 1.

51
00:02:07,770 --> 00:02:16,390
Okay let's take one more example so suppose let's take a bigger example so let's say 1 2 3 4 and 5 and

52
00:02:16,480 --> 00:02:17,430
6.

53
00:02:17,480 --> 00:02:19,940
So how many digits are there in this number.

54
00:02:19,940 --> 00:02:21,740
So there are six digits.

55
00:02:21,740 --> 00:02:22,270
Okay.

56
00:02:22,280 --> 00:02:30,270
What I will do I will break this number and then I will tell the equation to solve this smaller problem

57
00:02:30,480 --> 00:02:30,960
for me.

58
00:02:30,960 --> 00:02:35,760
So the occasion will return me 5 and then I will add plus 1.

59
00:02:35,930 --> 00:02:38,200
So it output will become 6.

60
00:02:38,220 --> 00:02:41,380
Okay let's try it in on one example.

61
00:02:41,520 --> 00:02:46,830
So suppose let's say our example is 4 0 2 5.

62
00:02:46,950 --> 00:02:47,440
Okay.

63
00:02:47,550 --> 00:02:50,010
So the value of end is good then goes to 1.

64
00:02:50,010 --> 00:02:52,360
So this number qualifies for our problem.

65
00:02:52,360 --> 00:02:57,800
Okay so what I'm planning to do here is I will break this number at this part okay.

66
00:02:57,870 --> 00:03:00,680
And I will tell recursion to solve this problem for me.

67
00:03:01,160 --> 00:03:01,640
Okay.

68
00:03:01,800 --> 00:03:09,260
So I will reach for zero to number and then again recursion big problem.

69
00:03:09,330 --> 00:03:15,160
I will call on this part so I will call on 40 again.

70
00:03:15,530 --> 00:03:23,870
We will break and we will call on this part so I will call on for again I will break at this part and

71
00:03:23,900 --> 00:03:24,830
I will call here.

72
00:03:24,830 --> 00:03:26,440
So this is zero basically.

73
00:03:26,540 --> 00:03:28,430
So I am calling 1 0.

74
00:03:28,760 --> 00:03:33,000
So this will be our base case okay.

75
00:03:33,060 --> 00:03:34,700
This will be our base case.

76
00:03:34,740 --> 00:03:36,150
So what it will done.

77
00:03:36,180 --> 00:03:39,440
It will return 0 now.

78
00:03:39,590 --> 00:03:44,760
Our form levels this part because it will give me the answer of this part and I will add plus 1.

79
00:03:44,780 --> 00:03:48,440
Okay so 0 plus 1.

80
00:03:48,470 --> 00:03:52,220
So I will return one here okay.

81
00:03:52,270 --> 00:03:56,540
So the onset of this part is 1 and I will add plus 1.

82
00:03:56,590 --> 00:04:03,050
So I will have done 2 Okay so does sort of this part of the equation told me downs of this part is too

83
00:04:03,560 --> 00:04:07,560
so and I will add plus one so I will done three.

84
00:04:07,760 --> 00:04:14,300
So that onset of this part discussion has told me the downside of this part is three and three plus

85
00:04:14,300 --> 00:04:14,610
one.

86
00:04:14,820 --> 00:04:19,220
So our output will be full which is our correct output which is the correct output.

87
00:04:19,220 --> 00:04:19,670
Okay.

88
00:04:20,890 --> 00:04:28,170
So if this is n this whole number is n so 4 0 2 5.

89
00:04:28,420 --> 00:04:34,110
If this is n now what is 4 0 2 so 4 0 2.

90
00:04:34,510 --> 00:04:36,070
This is and by then.

91
00:04:37,520 --> 00:04:38,140
Okay.

92
00:04:38,140 --> 00:04:40,870
So in Deja upon Deja will we end in Deja.

93
00:04:40,900 --> 00:04:51,140
So 4 0 2 5 4 so 4 0 2 5 4 divided by 10 will not be 4 0 2.5.

94
00:04:51,250 --> 00:04:52,990
It will be for it'll do we.

95
00:04:53,200 --> 00:04:56,050
Because we remember it digit upon integer will we in danger.

96
00:04:56,140 --> 00:04:56,450
Okay.

97
00:04:56,470 --> 00:04:58,850
Digital divide won't be there will be in okay.

98
00:04:59,320 --> 00:05:02,200
So I will write a function count.

99
00:05:02,200 --> 00:05:07,720
So this current function will take and as input what we have to do we have to break our problem.

100
00:05:07,750 --> 00:05:12,910
So what this current function do is it will take an integer n and it will tell me the number of digits

101
00:05:12,910 --> 00:05:13,950
present in n.

102
00:05:14,590 --> 00:05:17,050
So what I will do I will give.

103
00:05:17,080 --> 00:05:19,590
I will call the function on end by 10.

104
00:05:19,930 --> 00:05:21,070
So count will count.

105
00:05:21,070 --> 00:05:26,290
Function will give me how many digits are present in that number and by then basically leave the value

106
00:05:26,290 --> 00:05:28,500
of end is 4 0 2 5.

107
00:05:28,600 --> 00:05:31,160
Then what I'm calling I'm calling 1 4 0 2.

108
00:05:31,210 --> 00:05:35,440
So the equation will tell me that the number of digits column function will tell me the number of digits

109
00:05:35,470 --> 00:05:37,120
present in this is 3.

110
00:05:37,150 --> 00:05:39,310
Now what I have to do I have to add plus 1.

111
00:05:39,820 --> 00:05:42,330
So if I will add plus 1 I will get the problem.

112
00:05:42,850 --> 00:05:45,520
I will get the solution of the bigger problem let's count often.

113
00:05:45,910 --> 00:05:51,060
Okay so this will be our recursive case okay.

114
00:05:51,070 --> 00:05:53,710
And that will be a success if the value of any 0.

115
00:05:53,710 --> 00:05:55,100
I have to return 0.

116
00:05:55,150 --> 00:06:01,930
Okay now one thing that you may can get confused is if the value find the 0 0 5 you are not returning

117
00:06:01,970 --> 00:06:03,250
when we are in order.

118
00:06:03,250 --> 00:06:08,770
Don't need one here because initially I took a look at the value a friend will be good then order goes

119
00:06:08,770 --> 00:06:09,850
to 1.

120
00:06:09,850 --> 00:06:11,910
So this is basically invalid input.

121
00:06:12,040 --> 00:06:13,720
Okay this will be invalid.

122
00:06:13,720 --> 00:06:17,090
That's why I'm returning 0 here okay.

123
00:06:17,120 --> 00:06:21,530
So let's write the code and then we will draw this diagram again.

124
00:06:21,530 --> 00:06:23,170
So what do we that are done by Britain.

125
00:06:23,170 --> 00:06:26,460
I will be in danger okay because I have got it done.

126
00:06:26,460 --> 00:06:28,280
How many did your child present.

127
00:06:28,460 --> 00:06:34,910
So let's write the function count it will take a number n and we have to find how many digits out peasant

128
00:06:34,940 --> 00:06:43,330
in the number and so base case will be so this is our base case and base case is very simple.

129
00:06:43,350 --> 00:06:45,680
If the value of any 0.

130
00:06:45,960 --> 00:06:49,400
So how many did you decide peasant 0 digits at present.

131
00:06:49,850 --> 00:06:55,940
Okay because this is invalid input then again recursive case

132
00:06:58,790 --> 00:07:07,570
so recursive case small output small answer so a small answer is if you want to calculate number of

133
00:07:07,570 --> 00:07:11,460
digits in n then calculate the number of digits and then by 10.

134
00:07:11,890 --> 00:07:12,370
Okay.

135
00:07:12,490 --> 00:07:14,100
And then the calculation part

136
00:07:17,390 --> 00:07:19,050
so conclusion part is very simple.

137
00:07:20,160 --> 00:07:24,370
After calculating this more long said I have to add plus one and they're done.

138
00:07:24,480 --> 00:07:26,370
And let's test our function.

139
00:07:26,370 --> 00:07:35,170
So I'm calling this function count for let's say 7 8 2 0.

140
00:07:35,560 --> 00:07:39,540
Okay I'm calling this function 4 7 2 0.

141
00:07:39,540 --> 00:07:43,150
Now let's run our file so our output should be for data four digits.

142
00:07:43,170 --> 00:07:43,410
Okay

143
00:07:46,730 --> 00:07:51,770
so I would put this forward civil code is working fine now after writing the code with the help of PMI

144
00:07:51,950 --> 00:07:54,850
with what we will do we will try to do that and our goal.

145
00:07:54,890 --> 00:07:58,670
Basically we will try to draw the diagram so that we can have a better understanding.

146
00:07:58,770 --> 00:08:08,330
Okay so 7 8 2 0 the value of land is 7 8 2 0 so 7 8 2 0 okay.

147
00:08:08,550 --> 00:08:12,710
So this is not the case 2 0 7 0 2 0 is not close to zero.

148
00:08:12,710 --> 00:08:14,260
So line number 10.

149
00:08:14,270 --> 00:08:16,110
I will call an end by 10.

150
00:08:16,370 --> 00:08:24,830
So I will call on 7 8 2 then again I will come out this line.

151
00:08:24,840 --> 00:08:27,620
So basically 7 8 2 0 is waiting at line number 10.

152
00:08:27,690 --> 00:08:30,070
Senator 2 is waiting at line number 10.

153
00:08:30,150 --> 00:08:31,990
Then I will call in 7.

154
00:08:32,460 --> 00:08:34,280
Again I will call on this function.

155
00:08:34,290 --> 00:08:36,420
So it will wait at line number 10.

156
00:08:36,490 --> 00:08:40,010
It will call on 7 7 is not to question 0.

157
00:08:40,050 --> 00:08:41,790
This also will headline number 10.

158
00:08:41,850 --> 00:08:47,130
So it will call long 0 okay and by 10 so 7 by 10 will be 0.

159
00:08:47,130 --> 00:08:50,090
So if the value of any 0 I returning 0.

160
00:08:50,400 --> 00:08:51,640
So I will return 0.

161
00:08:52,110 --> 00:08:54,840
So 7 was waiting at line number 10.

162
00:08:54,890 --> 00:08:57,370
Salvador the real number Densmore lines up plus 1.

163
00:08:57,600 --> 00:09:04,070
Okay so the value of small arms that was 0 so what 7 Miller done small Lancer plus 1.

164
00:09:04,080 --> 00:09:05,630
So it will return 1.

165
00:09:05,910 --> 00:09:13,700
Now here the value of small lines that is 1 again I have done smaller small said plus 1 so I will return

166
00:09:13,710 --> 00:09:16,780
to the value of small lines.

167
00:09:16,780 --> 00:09:22,080
That is to say I have the right and small answer plus 1 so I will return 3.

168
00:09:22,090 --> 00:09:24,610
Then I have to write down small lines that plus 1.

169
00:09:24,640 --> 00:09:29,110
So I hate the value of small lines that is 3 so I have to attend 3 plus 1 which is 4.

170
00:09:29,470 --> 00:09:33,160
Okay so 4 is our answer 4 7 8 2 0.

171
00:09:33,190 --> 00:09:36,470
Okay so I have 70 to 0.

172
00:09:36,670 --> 00:09:39,090
Then I beg this number I.

173
00:09:39,490 --> 00:09:43,330
I call that equation on this part of the equation.

174
00:09:43,450 --> 00:09:45,200
So this is 7 8 2.

175
00:09:45,270 --> 00:09:46,820
I big this number.

176
00:09:47,080 --> 00:09:49,370
Recursion I call the equation on this part.

177
00:09:49,720 --> 00:09:51,500
So this is 78.

178
00:09:51,640 --> 00:09:53,040
I big this number.

179
00:09:53,040 --> 00:10:00,600
The equation will call on this part I break this number recursion will call on this part so it will

180
00:10:00,600 --> 00:10:02,750
be 0 so 0 will return 0 from it.

181
00:10:02,790 --> 00:10:04,830
And 0 plus 1.

182
00:10:04,920 --> 00:10:07,780
So I will return when one plus one.

183
00:10:07,890 --> 00:10:10,850
So I will return to 2 plus 1.

184
00:10:10,860 --> 00:10:13,820
I will return 3 3 plus 1.

185
00:10:13,890 --> 00:10:15,420
I will return food.

186
00:10:15,470 --> 00:10:20,180
Okay so in short you can understand it like this way.

187
00:10:20,190 --> 00:10:25,620
I want to calculate the number of digits present in this part present in the numbers 7 8 2 0.

188
00:10:25,620 --> 00:10:30,210
I will break the number because the questions is vague the number will big the bigger problem and the

189
00:10:30,210 --> 00:10:34,440
smaller problem and I am calling recursion on this part.

190
00:10:34,440 --> 00:10:38,010
So the equation will tell me you do not we have to assume okay.

191
00:10:38,220 --> 00:10:42,090
I told you we have to assume so we have to assume that the equation will tell me the answer of this

192
00:10:42,090 --> 00:10:42,810
party's tree.

193
00:10:43,590 --> 00:10:49,260
Okay now you do not have to think well how does that tree assume that the recursion will give me the

194
00:10:49,260 --> 00:10:50,100
answer tree.

195
00:10:50,250 --> 00:10:56,970
So recursion gives me the answer tree and then I will add plus 1 so 3 plus 1 and the answer is four.

196
00:10:57,450 --> 00:11:03,860
Okay so I am assuming here that and by then common function will give me the value.

197
00:11:04,090 --> 00:11:05,500
Give me the answer for this part.

198
00:11:05,500 --> 00:11:10,590
So the answer for this one will come out to be tree and then I am returning 3 plus 1 which is 4.

199
00:11:10,630 --> 00:11:13,200
Okay so I hope you understood the code.

200
00:11:13,420 --> 00:11:13,710
Okay.

201
00:11:13,720 --> 00:11:15,740
The problem was very very simple.

202
00:11:15,820 --> 00:11:17,170
Okay thank you.
