1
00:00:02,180 --> 00:00:02,910
Hi, everyone.

2
00:00:02,930 --> 00:00:09,020
So in this video, we are going to solve this question, find the lost index of the element so it will

3
00:00:09,020 --> 00:00:14,330
be provided to you and say the element of it is five, five, six, five and six.

4
00:00:14,870 --> 00:00:16,280
And the indexes are.

5
00:00:17,510 --> 00:00:19,950
So zero, one, two, three and four.

6
00:00:20,360 --> 00:00:24,140
So what do you need to do, given a value to the value of excess five?

7
00:00:24,410 --> 00:00:27,260
So you want to find five, but you need to retain the last.

8
00:00:27,800 --> 00:00:30,390
So five is present here, here and here.

9
00:00:30,680 --> 00:00:33,170
So but I need to return the last index.

10
00:00:33,710 --> 00:00:36,260
So the correct output will be three, four, five.

11
00:00:36,260 --> 00:00:42,340
The correct output will be three, four, six, six, spread into the next two as well as at index four.

12
00:00:42,620 --> 00:00:46,130
But since I need to return the last index, I will return four.

13
00:00:46,880 --> 00:00:49,440
And similarly, if I want to find out then.

14
00:00:49,730 --> 00:00:53,710
So 10 is not present inside this area, so the output will be minus one.

15
00:00:54,680 --> 00:00:59,180
So I hope you understood my question so we can easily discussion with the help of loop.

16
00:01:00,580 --> 00:01:05,970
So how is all this question with the help of all the security we need to find out the last.

17
00:01:07,150 --> 00:01:08,240
So we're finding out the last.

18
00:01:08,350 --> 00:01:14,560
Next what we will do, we will it over the area from and to start, we will trade over the area like

19
00:01:14,560 --> 00:01:14,950
this.

20
00:01:15,650 --> 00:01:19,870
We will start protecting the area from and and we will trade in this fashion.

21
00:01:20,350 --> 00:01:20,880
Simple.

22
00:01:21,070 --> 00:01:27,500
So as soon as you will find the value, as soon as you are able to find your value X, you will return

23
00:01:27,520 --> 00:01:28,140
the index.

24
00:01:28,690 --> 00:01:33,220
But since we are discussing about the equation, so we will solve this question using recursion.

25
00:01:34,930 --> 00:01:41,020
So if you remember the last video, we saw the question first, and so for finding out the first next,

26
00:01:41,410 --> 00:01:47,800
I was traversing the area like this as soon as you will find the element, Yolla done so for finding

27
00:01:47,800 --> 00:01:48,610
out the next.

28
00:01:48,680 --> 00:01:52,120
But I will do I will traverse my area like this.

29
00:01:53,120 --> 00:01:59,900
So as soon as I will find out the value, I will return the index and I told you for iterating over

30
00:01:59,900 --> 00:02:01,160
the area using recursion.

31
00:02:01,190 --> 00:02:02,380
We will take a variable.

32
00:02:03,020 --> 00:02:03,740
So what?

33
00:02:03,740 --> 00:02:10,150
Finding out the first index I took of it, I will start from index zero and I will reach at this index.

34
00:02:10,160 --> 00:02:12,740
And similarly, I will do exactly the same approach.

35
00:02:13,010 --> 00:02:14,570
I will start from this index.

36
00:02:15,380 --> 00:02:17,350
I will start from index and minus one.

37
00:02:17,660 --> 00:02:20,540
Then I will over the using recursion.

38
00:02:20,780 --> 00:02:24,350
And if I reach this index, so this index is minus one.

39
00:02:24,680 --> 00:02:28,840
So if I reach index minus one, that means value not found, value not found.

40
00:02:28,850 --> 00:02:31,790
And similarly if I reaches and so value not found.

41
00:02:32,090 --> 00:02:35,310
So this was the case for finding out the first element.

42
00:02:35,570 --> 00:02:41,410
So this is finding out the first index and this is the problem for finding out the last index.

43
00:02:41,600 --> 00:02:46,460
If you want to find out the last or next, the value of I will start from minus one will move in this

44
00:02:46,460 --> 00:02:46,970
direction.

45
00:02:47,150 --> 00:02:51,140
If the index I reach is minus one, that means value not found.

46
00:02:51,440 --> 00:02:53,670
So this isn't next zero and this is an next minus one.

47
00:02:53,780 --> 00:02:54,960
So let's write the code.

48
00:02:56,330 --> 00:03:00,560
So what we'll do, we will return integer because we need to return the index.

49
00:03:01,010 --> 00:03:02,570
The name of the function is lost.

50
00:03:02,650 --> 00:03:05,360
Next, we will take editor's input.

51
00:03:05,750 --> 00:03:07,660
We will take how many elements are there.

52
00:03:08,150 --> 00:03:13,820
We will take the value which we want to search for and we will take I associate the name of the function

53
00:03:13,820 --> 00:03:14,720
is Lost year next.

54
00:03:17,220 --> 00:03:24,210
At a number of elements is faith, the value of, let's say I want to search for food and I have to

55
00:03:24,210 --> 00:03:28,450
start trading from the end, so what is the end of next five minus one?

56
00:03:28,860 --> 00:03:30,420
So an index is for.

57
00:03:32,000 --> 00:03:39,150
So in order to write the code, so we discussed that if I reaches minus one.

58
00:03:39,440 --> 00:03:41,080
So when will I reach minus one?

59
00:03:41,540 --> 00:03:43,040
So I will start reading.

60
00:03:43,760 --> 00:03:45,480
So this is in mix and minus one.

61
00:03:45,770 --> 00:03:49,150
So I am passing the last index and it is of five.

62
00:03:49,160 --> 00:03:51,050
So the last two, Nexus five minus one.

63
00:03:51,470 --> 00:03:53,050
So I am writing like this.

64
00:03:53,300 --> 00:03:56,880
So if I had this index, this is minus one index, this is your next.

65
00:03:57,200 --> 00:04:02,880
So after searching the entirety, if I reach this index that means the value is not present.

66
00:04:03,110 --> 00:04:07,880
So if the value is not present, I can return in value the next.

67
00:04:07,910 --> 00:04:10,040
Let's say I am returning minus one.

68
00:04:10,160 --> 00:04:13,670
So minus one is an invalid index or you can return minus five.

69
00:04:13,850 --> 00:04:15,660
Minus five is also invalid index.

70
00:04:16,010 --> 00:04:17,959
So for example, I am returning minus T.

71
00:04:18,140 --> 00:04:22,490
If I not found I will return minus three, otherwise I will check.

72
00:04:22,670 --> 00:04:29,900
So if Yafai is equal to X, so in that case I can return I.

73
00:04:30,470 --> 00:04:33,260
So basically I will start outrating from the end.

74
00:04:33,960 --> 00:04:42,320
So if I reach Index I and this index value X is present for the first time from the last, it will be

75
00:04:42,320 --> 00:04:43,340
present for the first time.

76
00:04:43,340 --> 00:04:44,680
So I will return this index.

77
00:04:45,140 --> 00:04:51,980
So I will return, I am returning at the rates but I need to do, I need to do a minus minus so I need

78
00:04:51,980 --> 00:04:56,120
to come one step back i.e. minus minus means I will pass i.e. minus one.

79
00:04:57,580 --> 00:05:00,010
So I will call the function there done.

80
00:05:02,020 --> 00:05:02,420
Next.

81
00:05:03,910 --> 00:05:12,070
Eddie and Alex and I need to move one step back, so I will do I mean, this one and I think our goal

82
00:05:12,070 --> 00:05:14,250
will work so for this thing.

83
00:05:14,710 --> 00:05:16,030
So I want to search for food.

84
00:05:16,150 --> 00:05:18,580
So the last two Nexus food, so outputted before.

85
00:05:21,170 --> 00:05:23,880
So the output is four and four is the right output.

86
00:05:24,680 --> 00:05:32,960
So let's take let's create a new every five, five, six, five, six and seven.

87
00:05:33,290 --> 00:05:36,020
So let's say I want to search for six.

88
00:05:36,230 --> 00:05:37,360
So what is the last element?

89
00:05:37,370 --> 00:05:38,210
How many elements are there?

90
00:05:38,240 --> 00:05:40,370
One, two, three, four, five and six.

91
00:05:40,790 --> 00:05:41,860
Six elements are there.

92
00:05:41,870 --> 00:05:46,490
So the value of any six and the last element will be five in the next five.

93
00:05:46,970 --> 00:05:50,950
So what I'm doing here is total number of elements present day six.

94
00:05:51,410 --> 00:05:53,650
I want to find the next four six.

95
00:05:53,690 --> 00:05:54,830
So this is zero.

96
00:05:55,100 --> 00:05:56,180
One and next to the next three.

97
00:05:56,180 --> 00:05:56,870
And the next four.

98
00:05:57,170 --> 00:05:58,610
So output should be index for.

99
00:05:59,880 --> 00:06:03,750
And the value of eight is six minus one.

100
00:06:04,970 --> 00:06:08,870
And maintenance on basically so the correct output is I should get four.

101
00:06:09,980 --> 00:06:11,000
I should get four.

102
00:06:12,310 --> 00:06:13,420
So I am getting four.

103
00:06:14,550 --> 00:06:18,340
And now let's also test our function for the value of life.

104
00:06:18,390 --> 00:06:22,650
I want to search for five so next zero index on an extra index three.

105
00:06:22,920 --> 00:06:24,060
So output should be three.

106
00:06:25,030 --> 00:06:29,390
Output is coming out to be three and let's test for invalid values.

107
00:06:29,410 --> 00:06:30,550
I want to search for ten.

108
00:06:31,030 --> 00:06:34,360
So output should be minus three because that is not pleasant.

109
00:06:34,990 --> 00:06:37,030
So output is coming out three, minus three.

110
00:06:37,840 --> 00:06:41,020
So our function is working and how it is working.

111
00:06:41,030 --> 00:06:44,320
So I told you, I already explained to you many times.

112
00:06:45,280 --> 00:06:51,340
I am reading from the end to start and as soon as I will find I value.

113
00:06:52,310 --> 00:06:58,640
As soon as I will find the value, I will return the index, as soon as I find the value, I am returning

114
00:06:58,640 --> 00:07:03,600
the index and for moving back, for moving one step back, I am doing I am minus one.

115
00:07:04,340 --> 00:07:07,070
So how it will work for this, Solich?

116
00:07:08,610 --> 00:07:16,740
Let's write another function, so five, five, six, five, six and seven, so I is standing at this

117
00:07:16,740 --> 00:07:20,820
index, so what I will do, I will check so I is not equal to minus one.

118
00:07:21,060 --> 00:07:26,760
And let's say I want to search for five, I want to search for five and seven is not close to five.

119
00:07:27,210 --> 00:07:29,340
So call that equation and do eight minus one.

120
00:07:29,340 --> 00:07:33,180
So call that equation and it will remain same and same and same.

121
00:07:33,180 --> 00:07:33,870
Exact same.

122
00:07:33,870 --> 00:07:35,040
So they will remain same.

123
00:07:35,580 --> 00:07:38,490
Five, five, six, five, six, seven.

124
00:07:39,920 --> 00:07:42,870
Only the value of I will reduce my rent, so I will come here.

125
00:07:42,890 --> 00:07:49,120
So this is Avenue Y, so I is not minus one and five is not present.

126
00:07:49,370 --> 00:07:50,180
It is six.

127
00:07:50,540 --> 00:07:52,270
So again, I will call the recursion.

128
00:07:53,000 --> 00:07:54,980
So five five and it will remain the same.

129
00:07:54,980 --> 00:07:56,450
Number of elements will remain same.

130
00:07:56,840 --> 00:08:00,300
So I will move one step back, i.e. minus one.

131
00:08:00,740 --> 00:08:02,500
So I am moving one step back.

132
00:08:02,960 --> 00:08:10,740
This is I so I is not close to minus one and five is equal to the value which we want to search for.

133
00:08:11,000 --> 00:08:13,700
So I will return the next zero one two entry.

134
00:08:13,940 --> 00:08:18,340
So the value of I is three, I am returning the next, so I will return three.

135
00:08:18,560 --> 00:08:21,680
So whatever value you are getting you are just likely returning.

136
00:08:21,860 --> 00:08:24,460
So I will return three and I will return three.

137
00:08:24,680 --> 00:08:26,690
So that's how this function is working.

138
00:08:27,570 --> 00:08:28,990
OK, so what you can do.

139
00:08:29,450 --> 00:08:36,919
So instead of using this variable you can use this variable and also how so you just need to move one

140
00:08:36,919 --> 00:08:37,549
step back.

141
00:08:37,710 --> 00:08:38,140
Right.

142
00:08:38,480 --> 00:08:42,610
So for moving one step back, I am taking this variable and I am doing I am minus one.

143
00:08:43,460 --> 00:08:48,500
So what you can do, you can use this variable and and you can do and minus one.

144
00:08:49,950 --> 00:08:53,460
So what I want to say is let's copy this function.

145
00:08:55,010 --> 00:08:58,820
There's no need of a Nixey, you can also write like this.

146
00:08:59,780 --> 00:09:01,220
I'm not passing a Nixey.

147
00:09:02,240 --> 00:09:03,530
So this is next to.

148
00:09:04,520 --> 00:09:08,550
I will use the variable end because the variable is basically unused.

149
00:09:09,090 --> 00:09:12,680
OK, in this core difficulty, I'm not using the variable in.

150
00:09:13,590 --> 00:09:17,910
I'm not using the DeBelin, so instead of using the variable, instead of creating a new variable,

151
00:09:17,910 --> 00:09:24,220
I we can use the variable and so for moving, so for I am doing a minus one.

152
00:09:24,240 --> 00:09:28,330
So similarly for and what I will do, I will do and minus one.

153
00:09:29,010 --> 00:09:30,870
So let's remove it.

154
00:09:31,050 --> 00:09:32,730
I will do np minus one.

155
00:09:33,030 --> 00:09:33,510
Simple.

156
00:09:33,840 --> 00:09:37,190
Similarly I so I was the last of the next.

157
00:09:37,470 --> 00:09:39,960
So now the last year Nix's and minus one.

158
00:09:40,920 --> 00:09:43,170
Similarly, when an.

159
00:09:44,940 --> 00:09:45,870
Becomes zero.

160
00:09:46,980 --> 00:09:52,440
Urata is empty, so I think this will work and decis and minus one.

161
00:09:53,810 --> 00:09:56,000
So the working is exactly the same.

162
00:09:59,410 --> 00:10:06,280
See, the working of dysfunction and dysfunction is exactly the same, but bertan dysfunction, I am

163
00:10:06,280 --> 00:10:07,600
not using the variable in.

164
00:10:08,500 --> 00:10:14,430
So we to create this very melee when you have a variable which is unused, so I'm using the variable

165
00:10:14,440 --> 00:10:16,930
N and I just modified.

166
00:10:18,290 --> 00:10:22,370
Discord, so let's see whether this will work or not so lasting next to.

167
00:10:23,340 --> 00:10:24,270
Lasting next to.

168
00:10:27,710 --> 00:10:33,860
And you do not need to pass the value of I just need to pass any number of elements, so let's have

169
00:10:33,860 --> 00:10:34,220
a good.

170
00:10:36,430 --> 00:10:38,110
So this is last and next to.

171
00:10:44,330 --> 00:10:47,780
So Dan is not president insideout, that's why we are getting ministry.

172
00:10:51,520 --> 00:10:58,090
Now, let's give the value so I want to search for five, so the correct answer should be zero one,

173
00:10:58,090 --> 00:11:00,310
two and three, correct output should be three.

174
00:11:00,880 --> 00:11:02,550
So five is present at the next.

175
00:11:02,960 --> 00:11:04,240
So my goal is working.

176
00:11:04,540 --> 00:11:09,640
So basically what I want to say is, see, in this function, I'm not using very Baalen.

177
00:11:10,690 --> 00:11:12,040
So there are two ways.

178
00:11:13,430 --> 00:11:14,550
So first base.

179
00:11:14,750 --> 00:11:22,040
So the first phase removal, since there's no use of N. So why we are passing and so the first phase

180
00:11:22,040 --> 00:11:22,760
we can remove.

181
00:11:22,770 --> 00:11:28,670
And so this is our ability to second base if we do not want to remove any.

182
00:11:29,570 --> 00:11:32,300
If you do not want to remove, then you should remove a.

183
00:11:33,730 --> 00:11:34,930
Then you should remove a.

184
00:11:36,140 --> 00:11:43,370
So I am removing I and and is doing exactly the same work which I was doing, so I followed this second

185
00:11:43,370 --> 00:11:43,750
approach.

186
00:11:43,760 --> 00:11:45,230
I removed I very.

187
00:11:46,540 --> 00:11:54,080
I am removing a variable that is basically remove variable and because it is not used.

188
00:11:54,580 --> 00:11:55,770
So how it will work.

189
00:11:56,050 --> 00:11:56,740
So let's see.

190
00:11:57,770 --> 00:12:00,690
See, the basic approach of solving this problem is very simple.

191
00:12:01,190 --> 00:12:04,490
You need to start trading from the end to the start.

192
00:12:05,000 --> 00:12:06,290
So what is the lasting next?

193
00:12:07,770 --> 00:12:09,730
Last year, Nixon basically and minus one.

194
00:12:10,230 --> 00:12:12,390
So what I'm doing here is basically.

195
00:12:14,290 --> 00:12:18,130
See, we can make the we can work out like this.

196
00:12:18,550 --> 00:12:21,580
So what I'm doing, I am checking for this index.

197
00:12:22,970 --> 00:12:30,260
So this infixes and Minocin I am checking present here are not exits, present or not, if X is present,

198
00:12:30,260 --> 00:12:36,200
written down next, if X is present, effects is present, I am returning the index.

199
00:12:36,890 --> 00:12:41,870
Otherwise, what I will do, I will call the recursion on this area and the question will give me the

200
00:12:41,870 --> 00:12:42,350
index.

201
00:12:42,830 --> 00:12:48,020
So I am calling the recursion on this area so that it is E and the number of elements and minus one

202
00:12:48,260 --> 00:12:53,690
number of elements is then minus on Arazi and I am passing the value X, so I am calling the equation

203
00:12:53,690 --> 00:12:55,370
and the equation will give me the right answer.

204
00:12:56,210 --> 00:12:56,750
Simple.

205
00:12:56,900 --> 00:12:58,460
So that's how it is working.

206
00:12:58,680 --> 00:13:02,170
So let me try it in the score for you, for one example, so that you can understand.

207
00:13:02,180 --> 00:13:03,280
Let's write in for this.

208
00:13:04,070 --> 00:13:09,500
So five, five, six, five, six and seven and.

209
00:13:10,560 --> 00:13:11,590
I will check for this.

210
00:13:11,880 --> 00:13:15,870
So you want to search for five, so the value of X is five.

211
00:13:17,130 --> 00:13:21,480
We are passing a number of elements to the number of elements is basically one, two, three, four,

212
00:13:21,480 --> 00:13:22,110
five and six.

213
00:13:22,560 --> 00:13:23,630
So six.

214
00:13:24,650 --> 00:13:28,970
So first of all, I will check that is not empty, it is not empty.

215
00:13:29,140 --> 00:13:30,210
Check the last index.

216
00:13:30,280 --> 00:13:32,810
So I will check seven is not close to five.

217
00:13:32,840 --> 00:13:34,280
So this is next five.

218
00:13:34,310 --> 00:13:37,220
OK, so this is N minus one.

219
00:13:37,490 --> 00:13:38,590
This is and minus one.

220
00:13:38,600 --> 00:13:39,480
So next zero.

221
00:13:39,510 --> 00:13:40,130
Next one.

222
00:13:40,130 --> 00:13:41,630
And next to the next three.

223
00:13:41,630 --> 00:13:42,290
And next four.

224
00:13:44,080 --> 00:13:47,590
So I am taking seven is not close to five, so on this, Mollari.

225
00:13:48,920 --> 00:13:54,900
Five, five, six, five and six, number of elements, five, the value of access five.

226
00:13:55,970 --> 00:13:56,750
So now check.

227
00:13:57,700 --> 00:14:02,610
So size is not zero and six is not close to five, so call on the small area.

228
00:14:03,670 --> 00:14:06,310
So I am calling on the small area, six and five.

229
00:14:06,340 --> 00:14:12,110
This is my new number of elements for the reducing the number of elements and I want to search for five.

230
00:14:13,030 --> 00:14:15,190
So check the last element.

231
00:14:15,580 --> 00:14:19,300
So five is equal to five and size is not zero, size is not zero.

232
00:14:19,300 --> 00:14:22,360
And the last element we are checking for the last element.

233
00:14:22,570 --> 00:14:24,820
So if are able to find the next, you will return.

234
00:14:25,000 --> 00:14:26,350
So we are done and minus.

235
00:14:26,350 --> 00:14:28,020
And what is the value of and is four.

236
00:14:28,210 --> 00:14:29,800
So you are returning four minus one.

237
00:14:29,830 --> 00:14:31,600
You are turning three and three.

238
00:14:31,600 --> 00:14:32,430
Straight answer.

239
00:14:32,590 --> 00:14:33,630
So you will return three.

240
00:14:34,720 --> 00:14:39,370
So basically this small answer, this is returning three.

241
00:14:39,760 --> 00:14:42,670
That means X is present at the next three.

242
00:14:42,670 --> 00:14:45,400
Whatever value you are getting from the equation, you will likely return.

243
00:14:45,760 --> 00:14:46,990
So I will return three.

244
00:14:47,320 --> 00:14:51,400
So basically value five is present at the next three.

245
00:14:51,560 --> 00:14:53,790
That's why you are getting three from this area.

246
00:14:54,280 --> 00:14:56,350
So whatever value you are getting, you will return.

247
00:14:56,380 --> 00:14:57,430
So I will return three.

248
00:14:59,070 --> 00:15:06,260
Simple, so that's how everything is working and this is a very simple case, so let's try to right

249
00:15:06,270 --> 00:15:08,610
let's take one example when we will hit the case.

250
00:15:09,090 --> 00:15:16,080
So let's take a small example, one, three, three and four NAMAROFF elements for let's say I want

251
00:15:16,080 --> 00:15:17,120
to search for five.

252
00:15:17,370 --> 00:15:18,960
So five is not present in the area.

253
00:15:19,260 --> 00:15:21,690
So the correct output will be minus three.

254
00:15:22,500 --> 00:15:24,420
Let's see how we will encounter minus three.

255
00:15:24,420 --> 00:15:26,440
So check size is not zero.

256
00:15:26,600 --> 00:15:27,870
Now check for the last element.

257
00:15:27,880 --> 00:15:29,490
So four is not close to five.

258
00:15:30,090 --> 00:15:30,870
So our area.

259
00:15:31,320 --> 00:15:32,550
So call on this, Mollari.

260
00:15:36,030 --> 00:15:38,170
So size is not zero.

261
00:15:38,730 --> 00:15:40,140
Check for the last element.

262
00:15:40,170 --> 00:15:48,230
So three is not close to five Colonus Mollari one entry number of elements to societies, not zero.

263
00:15:49,230 --> 00:15:51,450
For the last element, they are not equal.

264
00:15:53,610 --> 00:15:59,790
A smaller number of elements, one size is not zero for the last element, so one is not close to five

265
00:16:00,480 --> 00:16:05,960
on the smaller number of elements will become zero if the number of elements if the site is zero, you

266
00:16:05,970 --> 00:16:06,900
will return minus three.

267
00:16:06,900 --> 00:16:08,100
So you will have done minus three.

268
00:16:08,490 --> 00:16:12,170
And whatever value you are getting from the equation, you are just likely returning that value.

269
00:16:12,480 --> 00:16:17,940
So return minus three to done minus three there, done minus three and we will return minus three.

270
00:16:18,150 --> 00:16:20,060
So minus three means not present.

271
00:16:20,370 --> 00:16:22,040
So that's how you can solve this question.

272
00:16:22,650 --> 00:16:24,660
So there is one more way to solve this question.

273
00:16:24,960 --> 00:16:26,490
So how we are solving this question.

274
00:16:26,490 --> 00:16:27,750
We are iterating.

275
00:16:28,050 --> 00:16:30,300
So we are iterating, we are checking.

276
00:16:30,750 --> 00:16:34,270
First of all, we are checking whether the element is present at this index or not.

277
00:16:34,530 --> 00:16:40,500
And then we are calling that equation on this ETTY so we can solve this question like this.

278
00:16:41,610 --> 00:16:45,090
So in our current approach, we are moving from and to start.

279
00:16:46,370 --> 00:16:50,390
So let's discuss one more approach in which we will move from start to end.

280
00:16:51,370 --> 00:16:53,950
So what I'm planning to do is so first of all.

281
00:16:55,210 --> 00:17:01,300
I will call commission on this area, so the question will give me a valid next.

282
00:17:02,830 --> 00:17:05,030
Or it will in the index.

283
00:17:05,050 --> 00:17:12,319
So in the next, let's say minus one, minus one means not found and valid index means yes, it is present.

284
00:17:12,880 --> 00:17:19,900
So if it is not pleasant, if the value is not present, then what I will do, I will check is the value

285
00:17:19,900 --> 00:17:20,569
present here.

286
00:17:21,790 --> 00:17:27,400
So then I will check if if zero is equals two.

287
00:17:27,940 --> 00:17:29,870
So it will not be zero, it will be I.

288
00:17:30,370 --> 00:17:34,590
So I told you, when you want to add it over the array you will use it next time.

289
00:17:34,750 --> 00:17:35,940
So for our trading.

290
00:17:35,940 --> 00:17:38,930
What the idea I'm using index so I will check this index.

291
00:17:39,580 --> 00:17:44,290
So I will check if Elfy is equal to X is equal to X..

292
00:17:44,590 --> 00:17:46,330
So in that case I can return.

293
00:17:46,630 --> 00:17:48,070
In that case I cannot deny.

294
00:17:48,400 --> 00:17:50,830
In the ls part I will return minus one.

295
00:17:51,010 --> 00:17:52,450
So this Eddie.

296
00:17:53,370 --> 00:17:58,370
Is returning minus, that means when you're not found and values not present at this index also.

297
00:17:58,530 --> 00:18:00,720
So I will return minus one.

298
00:18:02,540 --> 00:18:07,800
If value found, if I'm getting a valid index, basically not minus one.

299
00:18:08,030 --> 00:18:12,420
So if values present here, then also I need to check for this.

300
00:18:13,040 --> 00:18:15,970
So it is it is possible, for example, you want to search for seven.

301
00:18:16,160 --> 00:18:20,620
So seven is present inside that eight and seven is also present here.

302
00:18:21,200 --> 00:18:22,480
Seven is also present there.

303
00:18:22,700 --> 00:18:27,980
So you will return a valid index, but we cannot just dial it on the index.

304
00:18:27,980 --> 00:18:33,560
First of all, you also need to check whether this index is containing that value or not.

305
00:18:33,860 --> 00:18:36,080
So if this index is containing that value.

306
00:18:37,360 --> 00:18:40,960
I will return that value, otherwise I will return.

307
00:18:42,130 --> 00:18:47,860
The value index, which we got, otherwise I will return that valid index simple.

308
00:18:48,220 --> 00:18:49,840
So now let us write the code.

309
00:18:50,050 --> 00:18:51,700
So this is our way of solving.

310
00:18:53,800 --> 00:18:54,520
So end.

311
00:18:55,740 --> 00:19:01,740
Last next t, so I will start out reading from start to end.

312
00:19:02,730 --> 00:19:11,550
Eddie, I need N and I so I will start reading from start to end, so this is lasting next three.

313
00:19:13,360 --> 00:19:19,000
And I need to pass I need to take X, has input X and I.

314
00:19:21,150 --> 00:19:24,340
The value of five will be zero, the value of zero.

315
00:19:24,360 --> 00:19:27,150
I will start our trading from start to end.

316
00:19:28,460 --> 00:19:29,890
So this case is very simple.

317
00:19:31,120 --> 00:19:34,220
Since we are dating from start to end.

318
00:19:34,390 --> 00:19:41,140
So if I reaches here, if I become Sequoia's twin, then the value is not present, so I will return

319
00:19:41,140 --> 00:19:43,060
invited and next I will return minus one.

320
00:19:43,640 --> 00:19:48,490
So if I is, then that means value not found.

321
00:19:48,820 --> 00:19:51,190
If value not found, you can return minus one.

322
00:19:52,010 --> 00:19:53,140
Otherwise result need to do.

323
00:19:54,260 --> 00:19:57,660
First, we will call that equation on this, Eddie.

324
00:19:58,160 --> 00:20:02,990
So where does this Eddie so this idea is E and and I plus one.

325
00:20:04,530 --> 00:20:06,390
So let's call it a collision on this, Eddie.

326
00:20:07,520 --> 00:20:13,040
And it will return index, so index in the remaining at.

327
00:20:15,330 --> 00:20:17,460
Let's call Lastra next three.

328
00:20:19,960 --> 00:20:20,470
Eddie.

329
00:20:21,420 --> 00:20:21,840
And.

330
00:20:23,360 --> 00:20:31,100
X and I plus one, so I'm calling the discussion on this Eddie index in the morning so it can be a valid

331
00:20:31,100 --> 00:20:32,990
index, it can be invalid index.

332
00:20:33,440 --> 00:20:40,210
So if this is an invalid index, OK, so there is one problem and it is a problem.

333
00:20:40,220 --> 00:20:46,360
So if you are getting index and we need to return the last valid index, we need to return the index.

334
00:20:46,760 --> 00:20:48,350
So we do not need to do all this.

335
00:20:49,560 --> 00:20:50,230
This is wrong.

336
00:20:51,060 --> 00:20:55,280
OK, you do not need to check for this because we need to return the last index.

337
00:20:55,740 --> 00:21:01,530
So if you are getting a valid index, you will likely return, you will directly return, otherwise

338
00:21:01,530 --> 00:21:02,590
you will do this step.

339
00:21:02,880 --> 00:21:03,960
Sorry for my mistake.

340
00:21:04,920 --> 00:21:07,020
So if the next remaining.

341
00:21:09,970 --> 00:21:12,610
It is minus one, that means I'm not able to find the value.

342
00:21:13,000 --> 00:21:20,500
So if the value is not present, if the value is not present and so I decided, let's check for this

343
00:21:20,500 --> 00:21:21,020
index.

344
00:21:21,700 --> 00:21:27,130
So if it is possible, that equals, of course, X, that is the criteria.

345
00:21:27,210 --> 00:21:28,030
That is the situation.

346
00:21:28,030 --> 00:21:28,930
I will return a.

347
00:21:29,930 --> 00:21:33,050
In the last part, you can simply done minus one.

348
00:21:35,000 --> 00:21:40,130
So when we will return minus one, so first time checking the value is not present.

349
00:21:41,720 --> 00:21:43,610
The value is not present inside the city.

350
00:21:44,460 --> 00:21:49,400
I'm getting minus one, I am getting minus one because the value is not present and value is not present

351
00:21:49,400 --> 00:21:50,620
at this position also.

352
00:21:50,870 --> 00:21:52,640
So basically, the value is not present in the.

353
00:21:52,940 --> 00:21:58,160
So I am returning minus one and India's part in the part.

354
00:21:58,190 --> 00:22:06,050
If this is a valid index and since I need to return the last index, so I will likely return this value.

355
00:22:09,270 --> 00:22:10,230
So in the early part.

356
00:22:11,110 --> 00:22:12,340
You can buy Claratyne.

357
00:22:15,410 --> 00:22:19,550
The value added, I think our function will work last year, next three.

358
00:22:20,560 --> 00:22:22,960
Six, five and zero, so let's call this function.

359
00:22:26,360 --> 00:22:27,980
OK, so if I.

360
00:22:29,510 --> 00:22:30,580
What is the error here?

361
00:22:32,730 --> 00:22:34,980
OK, so there's a problem.

362
00:22:38,890 --> 00:22:40,900
So the problem is this is basically a.

363
00:22:45,640 --> 00:22:47,950
So the output is three, so let's see.

364
00:22:50,970 --> 00:22:51,710
Let's again.

365
00:22:53,740 --> 00:22:56,930
So they are history and let us see why that is correct or not.

366
00:22:57,430 --> 00:23:02,020
So five, five, six, five, six and seven.

367
00:23:03,310 --> 00:23:08,380
So this is a big zero, next one and next to the next three and next for the next five, I want to search

368
00:23:08,380 --> 00:23:09,060
for five.

369
00:23:09,790 --> 00:23:10,830
So this is five.

370
00:23:11,230 --> 00:23:12,060
This is five.

371
00:23:12,100 --> 00:23:12,780
This is five.

372
00:23:13,090 --> 00:23:14,830
I need to return the last index.

373
00:23:15,070 --> 00:23:16,710
So last next is three.

374
00:23:16,960 --> 00:23:18,060
So I am returning three.

375
00:23:18,850 --> 00:23:20,440
So a function is working.

376
00:23:20,530 --> 00:23:22,570
So if you want, I can write in this code for you.

377
00:23:23,960 --> 00:23:26,090
So let's bring in how this court will look.

378
00:23:28,830 --> 00:23:30,440
So let's Grayden, for this example.

379
00:23:35,010 --> 00:23:39,870
So this is five, five, six, five, six and seven.

380
00:23:42,880 --> 00:23:44,140
So you want to search for.

381
00:23:45,270 --> 00:23:45,810
Five.

382
00:23:47,060 --> 00:23:51,440
The value of fire is initially zero, so the value of fire is initially zero.

383
00:23:52,510 --> 00:23:53,960
So what they will do, you will check.

384
00:23:53,980 --> 00:23:59,290
So I want to know, so you will call that equation so that it will remain same.

385
00:24:01,030 --> 00:24:06,890
So it will remain same and same, exact same, you are just doing a plus one, so everything will remain

386
00:24:06,890 --> 00:24:08,200
the same, just a plus one.

387
00:24:08,770 --> 00:24:11,100
So initially I was here, now I is here.

388
00:24:11,500 --> 00:24:13,020
So the value of is one.

389
00:24:13,630 --> 00:24:14,500
So what we do.

390
00:24:15,500 --> 00:24:20,930
I is not close to and so I will again call that equation, we will again call that equation.

391
00:24:21,460 --> 00:24:22,150
This is seven.

392
00:24:22,250 --> 00:24:28,690
So again, call that equation five, five, six, five, six and seven.

393
00:24:29,540 --> 00:24:32,600
So this is I the value of Y is two.

394
00:24:33,470 --> 00:24:39,050
So two is not close to end the value of this five and we want to search for five.

395
00:24:39,050 --> 00:24:40,370
The value of X is also five.

396
00:24:41,420 --> 00:24:48,560
So again, we will call the Cudgen five and it will remain same six, five, six and seven.

397
00:24:49,280 --> 00:24:52,990
OK, so this is basically the value which we want to search for.

398
00:24:53,000 --> 00:24:58,340
And the number of elements, number of elements is basically one, two, three, four, five, six number

399
00:24:58,340 --> 00:24:58,900
of elements.

400
00:24:59,140 --> 00:25:00,350
Sorry, this is X.

401
00:25:02,290 --> 00:25:04,440
So now you can check the value of I know.

402
00:25:06,570 --> 00:25:11,400
The value of history, and he's not close to end, so you will call one more time.

403
00:25:13,180 --> 00:25:16,780
Five, five, six, five, six and seven.

404
00:25:17,320 --> 00:25:21,460
The value of I use now four, so I is now here.

405
00:25:22,550 --> 00:25:24,310
So you will again call that equation.

406
00:25:26,630 --> 00:25:32,210
Five, five, six, five, six, seven.

407
00:25:32,330 --> 00:25:34,250
So now the value of is five.

408
00:25:35,400 --> 00:25:37,980
You are at this position you would call litigation.

409
00:25:40,460 --> 00:25:47,900
Five, five, six, five, six, seven, and now the value of I will become six.

410
00:25:47,930 --> 00:25:51,710
So now I is here, so you will return minus one.

411
00:25:52,340 --> 00:25:54,770
So basically this is returning minus one.

412
00:25:56,230 --> 00:26:01,180
So the value of andexanet remaining is minus one, if it is minus one, check for the correct position.

413
00:26:01,480 --> 00:26:03,760
So the value of is five for dissuasion.

414
00:26:03,760 --> 00:26:05,960
So seven equals equals five.

415
00:26:05,980 --> 00:26:07,070
I want to search for five.

416
00:26:07,270 --> 00:26:07,770
So no.

417
00:26:07,990 --> 00:26:08,990
So ten minus one.

418
00:26:09,160 --> 00:26:10,510
So it will be done minus one.

419
00:26:13,760 --> 00:26:18,320
So we are getting minus one from Dedecker, so we are getting minus and from the equation, we are getting

420
00:26:18,320 --> 00:26:20,330
minus one check for the current position.

421
00:26:20,630 --> 00:26:24,740
So current position is containing six and six is not equal to five.

422
00:26:24,890 --> 00:26:27,870
I want to search for five, so I will return minus one.

423
00:26:28,430 --> 00:26:30,140
So this will return minus one.

424
00:26:31,710 --> 00:26:34,020
So I am getting my lesson from director John.

425
00:26:34,960 --> 00:26:40,450
So I am getting my innocence from dedication, so check for the current position now, so current position

426
00:26:40,450 --> 00:26:41,470
is containing five.

427
00:26:42,620 --> 00:26:51,140
So five is it to five, so I will return a what is a I is three, so I will return three.

428
00:26:52,920 --> 00:26:59,530
So I'm getting three from the so the value of andexanet and remaining estie, I'm getting three from

429
00:26:59,530 --> 00:26:59,980
the equation.

430
00:27:00,330 --> 00:27:08,880
So if you are getting it next, which is valid, so you will return always certainty.

431
00:27:09,810 --> 00:27:13,550
If you are getting a valid index, you are just back later to return.

432
00:27:13,560 --> 00:27:13,830
Three.

433
00:27:14,070 --> 00:27:20,130
If you are getting a valid index, you are just likely returning return three and three is the right

434
00:27:20,130 --> 00:27:20,550
answer.

435
00:27:20,940 --> 00:27:22,570
So that's how everything is working.

436
00:27:22,920 --> 00:27:25,580
So let's test the case when the value is not present.

437
00:27:26,400 --> 00:27:31,020
So if the value which I want to search for is 10, then is not inside already.

438
00:27:31,290 --> 00:27:34,510
So output should be minus one and we are getting minus one.

439
00:27:34,980 --> 00:27:36,690
So basically our goal is working.

440
00:27:37,660 --> 00:27:40,360
Descended from this video, I will see you in the next one.

