1
00:00:01,650 --> 00:00:02,320
Hi, everyone.

2
00:00:02,340 --> 00:00:06,080
So in the last video, we discussed the discussion, we up to one now.

3
00:00:06,120 --> 00:00:08,770
In this video, we will implement the brute force solution.

4
00:00:09,090 --> 00:00:11,210
So what is the brute force of brute forces?

5
00:00:12,060 --> 00:00:13,110
You have three options.

6
00:00:13,110 --> 00:00:14,580
So you can do in minus one.

7
00:00:14,790 --> 00:00:17,820
You can do it by two and you can do it by three.

8
00:00:18,750 --> 00:00:22,350
You can only do one by two if and only if the number is divisible by two.

9
00:00:22,590 --> 00:00:26,490
And similarly, you can only do it by three if the number is divisible by three.

10
00:00:27,060 --> 00:00:29,940
So brute force solution is all the possible.

11
00:00:29,950 --> 00:00:34,780
But try this, but try this part and try this part and take the minimum of them.

12
00:00:35,040 --> 00:00:38,580
So basically we will use recursion to implement the brute force solution.

13
00:00:39,570 --> 00:00:41,630
So, Indigo's, let us take an example.

14
00:00:41,640 --> 00:00:43,290
So let's see if the value of Venezuela.

15
00:00:43,320 --> 00:00:45,960
So what we will do, we will write also.

16
00:00:45,980 --> 00:00:48,230
So first option is decrease by minus one.

17
00:00:48,240 --> 00:00:49,800
So I will reach 11.

18
00:00:49,960 --> 00:00:52,040
Second option is to sell by two.

19
00:00:52,050 --> 00:00:53,290
So I will reach a six.

20
00:00:53,310 --> 00:00:54,980
So second option is to divide by two.

21
00:00:55,230 --> 00:00:58,340
And the third option is divide by these two by three.

22
00:00:58,620 --> 00:01:01,500
So I will alter column for now what I will do.

23
00:01:01,720 --> 00:01:04,420
So I will ask Rogozin what is the answer for 11?

24
00:01:05,040 --> 00:01:07,470
So what is the answer I want to reach when?

25
00:01:07,920 --> 00:01:08,730
What is the answer?

26
00:01:08,790 --> 00:01:14,050
If I want to reach from 11 to one selected, the answer is I will study on a variable X.

27
00:01:14,430 --> 00:01:18,740
Similarly, I will ask the question what is the answer for reaching from six to one?

28
00:01:18,750 --> 00:01:23,520
I will store the answer on variable Y and similarly I will ask the question what is the answer if I

29
00:01:23,520 --> 00:01:25,080
want to reach from four to one?

30
00:01:26,130 --> 00:01:30,250
And I was told I was very blessed and finally able to live with my answer.

31
00:01:30,270 --> 00:01:34,850
So my answer basically the minimum of one, so minimum of X, Y and Z.

32
00:01:35,040 --> 00:01:41,160
And obviously I have to add plus one because I took one bad, OK, one of these three following, but

33
00:01:41,160 --> 00:01:41,900
I took one bite.

34
00:01:41,910 --> 00:01:42,930
So that's a plus one.

35
00:01:43,650 --> 00:01:47,660
Now if the value of any seven, if the value of any seven.

36
00:01:47,850 --> 00:01:48,780
So what will happen.

37
00:01:48,780 --> 00:01:49,290
Seven.

38
00:01:49,290 --> 00:01:50,580
Seven will call on six.

39
00:01:50,610 --> 00:01:53,440
I can call minus one cancel call.

40
00:01:53,520 --> 00:01:55,010
So seven is not usable by two.

41
00:01:55,020 --> 00:01:56,430
So this call is not valid.

42
00:01:56,670 --> 00:01:58,260
Similarly, seven is not divisible by.

43
00:01:58,410 --> 00:01:59,620
So this call is not valid.

44
00:01:59,790 --> 00:02:03,330
So at this point for seven, I have only one solution.

45
00:02:03,330 --> 00:02:04,950
I have only one call for six.

46
00:02:05,880 --> 00:02:07,490
OK, I will only call on six.

47
00:02:08,310 --> 00:02:09,210
I cannot call.

48
00:02:10,810 --> 00:02:13,990
Because the seven is not deisel by two or three now.

49
00:02:14,160 --> 00:02:14,950
That's right, the cold.

50
00:02:18,860 --> 00:02:23,210
So I have this function and steps it is taking and as input and I have to reach one.

51
00:02:23,510 --> 00:02:25,590
So first let us discuss the best case.

52
00:02:26,150 --> 00:02:27,470
So what is the best case?

53
00:02:28,250 --> 00:02:29,440
What will be our best case?

54
00:02:30,050 --> 00:02:31,340
So basically is very simple.

55
00:02:31,820 --> 00:02:32,480
So if.

56
00:02:33,300 --> 00:02:36,210
I'm able to reach one if I'm standing at one.

57
00:02:38,050 --> 00:02:39,490
What is the minimum steps, more steps?

58
00:02:39,520 --> 00:02:45,030
Zero simple or you can also do so if the number is less than close to one, you can return zero.

59
00:02:45,250 --> 00:02:45,790
Simple.

60
00:02:46,960 --> 00:02:48,940
Now, let's do the recursive call.

61
00:02:50,160 --> 00:02:56,400
So I have three options, so the first option is let's do it in a variable X, the first option is let

62
00:02:56,400 --> 00:02:57,870
us call the function M. Steps.

63
00:03:00,020 --> 00:03:02,930
And minus one, so I'm stalling the inevitable.

64
00:03:03,500 --> 00:03:04,550
The second option is.

65
00:03:06,100 --> 00:03:06,860
What can I do?

66
00:03:06,880 --> 00:03:12,370
I can divide the number by two, and similarly, the third option is.

67
00:03:16,420 --> 00:03:18,460
Million steps and and Betty.

68
00:03:19,930 --> 00:03:23,830
But you cannot go alone and vital if the number is not, why do so?

69
00:03:23,830 --> 00:03:25,920
Basically, you can see an example here.

70
00:03:26,440 --> 00:03:27,280
So for seven.

71
00:03:28,410 --> 00:03:33,930
I can only call on six, I cannot call on seven by two, and similarly I cannot call seven by three

72
00:03:33,930 --> 00:03:37,110
because seven is not diesel by two and the seven is not diesel by three.

73
00:03:37,740 --> 00:03:39,510
So I have to write a check.

74
00:03:40,530 --> 00:03:41,350
So what can I do?

75
00:03:41,370 --> 00:03:42,450
So you have to write.

76
00:03:42,450 --> 00:03:43,230
I have a condition.

77
00:03:43,530 --> 00:03:48,270
So if the number is divisible by two, then only you can call.

78
00:03:52,780 --> 00:03:54,430
Then only you can go along and buy two.

79
00:04:00,820 --> 00:04:01,690
And similarly.

80
00:04:02,830 --> 00:04:08,740
I will have if the number is divisible by 10, then only I can go on and buy three.

81
00:04:18,370 --> 00:04:24,640
Now, after finding out X, Y and Z, what we have to do, we have to find our final output, so let's

82
00:04:24,640 --> 00:04:25,750
calculate our output.

83
00:04:28,480 --> 00:04:29,820
Let's calculate our answer.

84
00:04:36,080 --> 00:04:37,230
So what will be that answer?

85
00:04:37,580 --> 00:04:42,320
So I told you, I have to take M.F. also industry's main function.

86
00:04:42,330 --> 00:04:45,320
So this main function is in built function in C++.

87
00:04:45,620 --> 00:04:47,180
So I have to take a minimum of two things.

88
00:04:47,180 --> 00:04:49,680
So X, Y, Z.

89
00:04:50,710 --> 00:04:52,870
OK, so after take a minimum of two things.

90
00:04:52,880 --> 00:04:54,780
So actually this is wrong.

91
00:04:55,700 --> 00:05:03,230
So the inbuilt function in C++, so I have a function minimum, this function makes two arguments ENB

92
00:05:03,230 --> 00:05:07,210
and what it will return, it will return me the minimum of the two numbers.

93
00:05:07,610 --> 00:05:11,650
But here in this case, in our situation, I have Tinamba, X, Y and Z.

94
00:05:11,960 --> 00:05:15,190
Still, if you will write like this minimum of X, Y or Z.

95
00:05:15,470 --> 00:05:19,680
So obviously this is this will not work because the minimum function takes only two argument.

96
00:05:20,390 --> 00:05:24,700
So how can I use a minimum function to find the minimum of Tinamba?

97
00:05:24,890 --> 00:05:28,490
So I will write something like this min first number.

98
00:05:29,000 --> 00:05:33,150
And the second number is I will call a minimum function again and I will give Y and Z.

99
00:05:33,890 --> 00:05:35,390
So this is my first number.

100
00:05:35,930 --> 00:05:38,860
Then minimum function will find out the meaning of these two.

101
00:05:38,870 --> 00:05:41,750
So let's say the minimum is Y then this minimum function.

102
00:05:41,930 --> 00:05:44,100
This is the first argument and this is the second argument.

103
00:05:44,390 --> 00:05:48,620
So if you want to find out the minimum of three numbers, you can write like this.

104
00:05:49,190 --> 00:05:53,570
So actually, this minimum function, I think it is implemented in Zimet Liberi.

105
00:05:55,660 --> 00:06:01,390
So what I have to do, I have to find him involved in ambush, so I will use minimum function two times.

106
00:06:03,750 --> 00:06:10,470
And after finding out the minimum, after calculating of said, sorry, I have to do plus one also plus

107
00:06:10,470 --> 00:06:14,430
one as discussed and after calculating of it, I said we can return our answer.

108
00:06:15,060 --> 00:06:18,040
Simple now is our solution, right?

109
00:06:18,540 --> 00:06:22,190
So check the scope of BNZ so is very valid here.

110
00:06:22,230 --> 00:06:28,280
Know the scope of why is only headline number 14 and similarly, the scope of that is only the line

111
00:06:28,290 --> 00:06:29,000
number 17.

112
00:06:29,190 --> 00:06:32,090
So Y and Z are not defined headline number 20.

113
00:06:32,100 --> 00:06:36,080
So what I have to do, I have to write Y and Z above.

114
00:06:36,090 --> 00:06:37,920
So I have to declare Y and Z here.

115
00:06:38,750 --> 00:06:40,260
OK, so remove Integer from here.

116
00:06:41,870 --> 00:06:43,670
Now, is that right?

117
00:06:43,880 --> 00:06:46,530
So our goal is not right, why it is not right.

118
00:06:46,550 --> 00:06:49,540
So let us try to understand what is the problem with this cold?

119
00:06:49,850 --> 00:06:52,000
So let's say the value of an is seven.

120
00:06:52,610 --> 00:06:53,360
So what will happen?

121
00:06:53,360 --> 00:06:55,070
Seven will call on six.

122
00:06:55,070 --> 00:06:58,940
Seven cannot call because it is not the seven is not used by two.

123
00:06:58,940 --> 00:07:03,110
And similarly, we cannot call on seven by three because seven is not duCille by three.

124
00:07:03,500 --> 00:07:09,830
So I will call the occasional six and let's say it reaches one and let's say the answer is no steps

125
00:07:09,830 --> 00:07:10,730
is basically X.

126
00:07:11,240 --> 00:07:18,080
So what does Y contain since I only declare Y and Z, so Y and Z, they both contain garbage value.

127
00:07:19,510 --> 00:07:19,730
Why?

128
00:07:20,230 --> 00:07:25,930
They both contain garbage value and what I am doing at this line, I'm using the minimum function.

129
00:07:25,930 --> 00:07:29,770
I am trying to find out the minimum of X, Y and Z.

130
00:07:29,920 --> 00:07:31,390
So Y and Z are garbage.

131
00:07:32,410 --> 00:07:36,580
So what is the value of x axis, let's say so from six, I will reach.

132
00:07:37,700 --> 00:07:43,370
To and from two, I will be able to reach one, so the value of X is basically to OK, so access to

133
00:07:44,000 --> 00:07:48,850
Y is garbage, that is also garbage and I am taking the minimum of these three.

134
00:07:49,350 --> 00:07:50,510
So obviously this is wrong.

135
00:07:51,440 --> 00:07:52,500
So what can I do?

136
00:07:52,520 --> 00:07:58,540
So that means I have to initialize in garbage can be anything, garbage can be anything.

137
00:07:58,580 --> 00:08:01,130
So that means there is a need for initializing Y and Z.

138
00:08:01,310 --> 00:08:04,020
So can I put Y equals zero and that equals zero.

139
00:08:04,730 --> 00:08:06,800
So if you put viticultural that equals zero sum.

140
00:08:06,800 --> 00:08:13,760
What is the value of x axis two and if you will take the minimum of X, Y and Z, so it will come out

141
00:08:13,760 --> 00:08:16,270
to be zero and then you will add plus one.

142
00:08:16,280 --> 00:08:19,010
So zero plus one and then you will return your answer.

143
00:08:19,850 --> 00:08:22,390
So basically you will return one as your answer.

144
00:08:22,550 --> 00:08:24,800
And obviously one is wrong, one should be wrong.

145
00:08:24,800 --> 00:08:26,320
So your answer should be from seven.

146
00:08:26,330 --> 00:08:29,820
I will go six, then two and then one.

147
00:08:30,230 --> 00:08:34,100
So the correct answer is basically three and you are returning one.

148
00:08:34,340 --> 00:08:36,710
So what I have to do, one thing is very clear.

149
00:08:36,710 --> 00:08:38,179
I cannot initialize with zero.

150
00:08:39,080 --> 00:08:40,299
I cannot naturalizer zero.

151
00:08:40,309 --> 00:08:47,020
So what I will do, I will initialize y with plus infinity and I will initialize that with plus infinity.

152
00:08:47,420 --> 00:08:49,190
So if I will take the minimum.

153
00:08:49,860 --> 00:08:54,950
So minimum of excess to Y is plus infinity plus infinity.

154
00:08:55,100 --> 00:09:01,300
So the minimum will come out to be two and I will add plus one to two plus one is three.

155
00:09:01,310 --> 00:09:04,750
So I will return three as my answer entry is the right answer.

156
00:09:05,450 --> 00:09:07,800
And what is plus infinity so pleasant.

157
00:09:08,230 --> 00:09:10,730
It is nothing in C++ it is intermix.

158
00:09:10,730 --> 00:09:12,110
And what is the meaning of Interex.

159
00:09:12,120 --> 00:09:17,360
So the maximum number that can beta cancel the maximum number that can distort an integer variable.

160
00:09:19,990 --> 00:09:27,220
So it is very clear that I have to initialise Y and Z, so let's initialize so Y equals Z equals Intermix.

161
00:09:36,490 --> 00:09:42,430
OK, so I have initialised Y and Z, so now let us call our function now let us based our function.

162
00:09:43,030 --> 00:09:46,000
Soucy out the name of the Functionalism Insteps.

163
00:09:50,100 --> 00:09:51,420
And let's give the value in.

164
00:10:04,230 --> 00:10:05,850
OK, so let's start program.

165
00:10:09,060 --> 00:10:14,520
So let's say the value of any seven, so I would say is going to be three, the guys from seven, I

166
00:10:14,520 --> 00:10:18,550
will reach six from six to and from two, one, two, three steps.

167
00:10:21,620 --> 00:10:24,860
Now, let's say the value of NPS is basically 10.

168
00:10:26,110 --> 00:10:32,230
So the answer is coming out of Italy, so from then I will reach nine from nine three and then one to

169
00:10:32,230 --> 00:10:33,250
ten, nine, 11.

170
00:10:33,250 --> 00:10:35,920
So three steps forward and two steps.

171
00:10:37,150 --> 00:10:38,860
And now their distaste for 11.

172
00:10:40,930 --> 00:10:46,980
So for 11, the steps is coming out before, so let's check federal solution is quite wrong.

173
00:10:48,010 --> 00:10:53,950
So for 11, my gold is giving me output for wifehood because from 11 I can reach 10.

174
00:10:54,160 --> 00:10:55,990
From ten, I can reach nine.

175
00:10:55,990 --> 00:10:59,670
And from nine I can reach three and then one.

176
00:11:00,310 --> 00:11:03,350
OK, so four steps, one, two, three and four.

177
00:11:03,730 --> 00:11:05,560
So basically our goal is working fine.

178
00:11:06,070 --> 00:11:06,460
It goes in.

179
00:11:06,460 --> 00:11:08,770
Gold is working fine now.

180
00:11:10,270 --> 00:11:12,220
Now try to implement memorisation.

181
00:11:13,800 --> 00:11:19,440
OK, so try implementing memorisation solution, I will see you in the next one, Alloway.

