1
00:00:01,710 --> 00:00:02,440
Hi, everyone.

2
00:00:02,460 --> 00:00:08,730
So in this video, we are going to discuss this question, find the first index of the element so it

3
00:00:08,730 --> 00:00:12,180
will be provided to you and let the elements of the adays.

4
00:00:13,250 --> 00:00:21,270
Five, five, six, five and six, and these are the Nexus zero, one, two, three and four.

5
00:00:21,800 --> 00:00:25,120
So the question is there will be element to this element.

6
00:00:25,520 --> 00:00:27,040
Let's say the value of X is five.

7
00:00:27,380 --> 00:00:31,610
So five is present at index zero at the next one at the next three.

8
00:00:31,740 --> 00:00:34,220
But you need to return the first index.

9
00:00:34,670 --> 00:00:36,550
So the output for five should be zero.

10
00:00:38,030 --> 00:00:44,960
Similarly, if the value of sex is sex, so it is present at an next as well as at the next four buttons,

11
00:00:44,990 --> 00:00:46,930
we need to return the first index.

12
00:00:47,180 --> 00:00:48,380
So my answer will be to.

13
00:00:49,460 --> 00:00:54,920
Let's say you want to search for 10, so 10 is not present inside this area, so my output will be minus

14
00:00:54,920 --> 00:00:58,490
one Y minus one because minus one is an invalid index.

15
00:00:58,760 --> 00:01:05,040
So I need to return the index and minus one is invalid index so we can easily solved this discussion

16
00:01:05,090 --> 00:01:06,670
with the help of phone number by loop.

17
00:01:07,040 --> 00:01:12,410
So this area provided to you, you will just iterate over the area and as soon as you find the element,

18
00:01:12,410 --> 00:01:13,590
you will return the index.

19
00:01:14,030 --> 00:01:17,420
So using for Lopevi Loop to solve this problem is very simple.

20
00:01:17,780 --> 00:01:24,940
So what we will do to make this problem, we will use recursion so using it to solve this problem.

21
00:01:25,760 --> 00:01:28,620
So the question is also very simple to apply in this problem.

22
00:01:29,300 --> 00:01:30,860
So how we can apply recursion.

23
00:01:31,760 --> 00:01:36,960
So in the last video I discussed with you, I index how we can use our index.

24
00:01:36,980 --> 00:01:39,760
So I index is very similar to the volume.

25
00:01:40,070 --> 00:01:42,860
We will just iterate using the index.

26
00:01:43,340 --> 00:01:46,340
So our function will be we need to return an integer.

27
00:01:48,020 --> 00:01:50,570
And these are basically index function.

28
00:01:50,600 --> 00:01:53,360
I will take that as input, I will take a number of elements.

29
00:01:53,570 --> 00:01:56,520
I will take element which I want to find out and index.

30
00:01:56,930 --> 00:01:58,840
So initially, the value of five will be zero.

31
00:01:58,850 --> 00:02:02,710
I will pass the value of I zero from mean and what they need to do.

32
00:02:02,870 --> 00:02:09,949
So envelope what will do we will I treat using Nixey and as soon as you will find out the value you

33
00:02:09,949 --> 00:02:11,210
will return the index.

34
00:02:11,660 --> 00:02:12,990
So we do exactly the same.

35
00:02:13,640 --> 00:02:16,040
So if you are able to find out the value.

36
00:02:17,700 --> 00:02:21,840
You need to return the index, so I will return the index, return I.

37
00:02:23,670 --> 00:02:29,680
Simple otherwise, check for this position, if not found, go to next position and check, so for going

38
00:02:29,680 --> 00:02:31,710
into next position, I will call this function.

39
00:02:33,520 --> 00:02:36,490
And it will maintain the same X will remain the same.

40
00:02:36,730 --> 00:02:40,210
I just need to do a plus one to move to next position.

41
00:02:41,950 --> 00:02:47,350
So we are doing exactly the same approach, exactly the follow up approach using recursion.

42
00:02:48,530 --> 00:02:55,400
OK, so I will just I read I am meditating over Director Armatrading over the area using recursion.

43
00:02:57,740 --> 00:03:03,980
I am I reading over the area, so there are two ways for outrating, first, using the for loop or develop

44
00:03:04,220 --> 00:03:05,250
who I did over the area.

45
00:03:06,230 --> 00:03:09,670
So in this problem, I am using recursion to iterate over the area.

46
00:03:09,920 --> 00:03:12,520
So frustrating over the array we need index I.

47
00:03:13,130 --> 00:03:16,630
So I hope you got the question and how you can solve this question.

48
00:03:16,940 --> 00:03:18,140
So let us write the code.

49
00:03:20,570 --> 00:03:21,410
So what will do?

50
00:03:23,330 --> 00:03:28,340
Let's say the name of the function is that there will be integer because we are going to return the

51
00:03:28,340 --> 00:03:33,450
index and then the other function is first, first and then the first.

52
00:03:35,260 --> 00:03:41,470
So I will take it as input, I will take the number of elements cise.

53
00:03:42,410 --> 00:03:47,190
I will take the value which I want to find, and next, I do it right over the area.

54
00:03:47,780 --> 00:03:49,090
So basically it is very simple.

55
00:03:49,970 --> 00:03:51,640
So follow up what you will do.

56
00:03:51,860 --> 00:03:54,650
So if you are using for low priority over the area, what you will do.

57
00:03:56,040 --> 00:04:01,890
So you will start from zero, you will trade, and if you are not able to find a value, you will reach

58
00:04:02,400 --> 00:04:02,650
next.

59
00:04:02,730 --> 00:04:08,640
And so if you reach index and that means the value is not present and you will return minus one minus

60
00:04:08,640 --> 00:04:11,770
and miss in the index, basically the value not found.

61
00:04:12,330 --> 00:04:13,980
So we will do exactly the same.

62
00:04:15,190 --> 00:04:15,670
If.

63
00:04:17,450 --> 00:04:20,930
I equals sorry if.

64
00:04:22,350 --> 00:04:29,400
If I reaches if I reach the last index, basically, and if I reach index, and that means Vaillancourt

65
00:04:29,400 --> 00:04:33,840
not found, if we had not found, I will have done minus one simple.

66
00:04:35,320 --> 00:04:38,330
Otherwise, I am standing at the next site.

67
00:04:38,470 --> 00:04:39,760
Let's check for the next guy.

68
00:04:40,000 --> 00:04:42,190
So if if I equals X.

69
00:04:43,200 --> 00:04:50,010
So that means excess at the current index, so I will return the index, return I so envelope at will

70
00:04:50,010 --> 00:04:51,240
do so then.

71
00:04:51,940 --> 00:04:57,390
So this is the code for for loop equals zero elastin in AA plus plus.

72
00:04:59,170 --> 00:04:59,650
If.

73
00:05:00,850 --> 00:05:05,560
If I equals two X. You need to return the index, so I will return.

74
00:05:06,550 --> 00:05:10,510
And if I will come out of the for loop, that means I reach then.

75
00:05:10,760 --> 00:05:15,740
So if I reaches, then that means the value is not found.

76
00:05:16,090 --> 00:05:18,520
So in that case, you can return minus one.

77
00:05:20,240 --> 00:05:25,150
So that is how we can solve the problem with the help of Orlob, so we are doing exactly the same.

78
00:05:25,430 --> 00:05:29,570
If I if I stiches and if I do Jizan, I am returning my Nesson.

79
00:05:30,050 --> 00:05:31,910
I am standing at the correct position.

80
00:05:32,250 --> 00:05:33,950
I'm standing at the next day.

81
00:05:34,160 --> 00:05:37,070
So if X is present the next day, I will return.

82
00:05:37,070 --> 00:05:39,050
I exactly like this.

83
00:05:39,450 --> 00:05:45,050
Otherwise, if it is not present at the next day, we will move to the next index and we will check.

84
00:05:45,680 --> 00:05:51,580
So for moving to next and next I do I placeless but here I will do, I will pass I plus one.

85
00:05:52,100 --> 00:05:54,140
So now we need to search.

86
00:05:58,270 --> 00:06:07,150
So now we need to search, we will move ahead and we will search, so Eddie and I plus one and that's

87
00:06:07,150 --> 00:06:07,370
all.

88
00:06:07,720 --> 00:06:09,130
So this is the complete goal.

89
00:06:09,550 --> 00:06:17,470
So for moving ahead in the area with 80 plus plus so far, moving ahead for migrating, fighting over

90
00:06:17,470 --> 00:06:18,500
the area, using recursion.

91
00:06:18,520 --> 00:06:21,070
I will do I plus one simple.

92
00:06:23,040 --> 00:06:24,600
So let's have a good.

93
00:06:25,530 --> 00:06:27,090
Copy the function, Foster Nix.

94
00:06:29,920 --> 00:06:31,410
Out foster niks.

95
00:06:32,580 --> 00:06:37,590
Eddie size is five, let's say I want to search for.

96
00:06:38,530 --> 00:06:39,010
For.

97
00:06:39,900 --> 00:06:43,380
And I will be zero, I will start searching from index zero.

98
00:06:44,890 --> 00:06:51,700
So let's say for this prison here also and for this prison.

99
00:06:53,850 --> 00:06:57,510
Here also, so the correct outputs would be when the next one.

100
00:07:01,150 --> 00:07:03,070
So for this president, the next one.

101
00:07:05,730 --> 00:07:12,000
Let's consider one example when the element is not president, so I want to search for five, so five

102
00:07:12,000 --> 00:07:15,960
is not present inside the third, but will be minus one.

103
00:07:17,230 --> 00:07:18,580
So output is minus one.

104
00:07:20,710 --> 00:07:25,960
Now let's search for three teens present at next to.

105
00:07:27,630 --> 00:07:29,880
So please present at next to.

106
00:07:31,180 --> 00:07:33,740
So our goal is working now.

107
00:07:33,760 --> 00:07:34,960
Let's write a novel called.

108
00:07:35,930 --> 00:07:42,650
How it is working, so it is exactly like the for loop you can see we are using for loop, we are just

109
00:07:42,650 --> 00:07:47,660
iterating, we are just iterating over the area using recursion.

110
00:07:48,050 --> 00:07:50,490
So let's get another caller on this example.

111
00:07:50,510 --> 00:07:54,430
So I have one, four, three, four and four.

112
00:07:55,160 --> 00:07:56,840
So a number of elements is five.

113
00:07:57,380 --> 00:08:01,760
I want to search for for let's say I want to search for four.

114
00:08:01,910 --> 00:08:03,710
So the output should be one.

115
00:08:05,130 --> 00:08:10,890
So this is index zero, index one, index to index three and index four, so currently what is the value

116
00:08:10,890 --> 00:08:11,040
of.

117
00:08:11,250 --> 00:08:12,520
So this is the value of I.

118
00:08:12,550 --> 00:08:13,530
I am passing zero.

119
00:08:14,690 --> 00:08:17,120
So check, so I check.

120
00:08:17,150 --> 00:08:19,890
So zero is not close to five, then check.

121
00:08:19,910 --> 00:08:22,620
So one is, of course, two for no.

122
00:08:22,640 --> 00:08:24,820
So I will move ahead, so I will come here.

123
00:08:25,730 --> 00:08:29,180
So if you are not able to understand it like this, what will happen?

124
00:08:29,450 --> 00:08:33,110
Because call one, four, three, four, four.

125
00:08:33,110 --> 00:08:34,010
And this is a.

126
00:08:35,390 --> 00:08:43,280
So, again, this is an excellent one, is not equals two and five and so forth is equal to four, so

127
00:08:43,280 --> 00:08:49,120
Afie is equal to X, you've done I, so the value of phase one when so this function will return one.

128
00:08:49,490 --> 00:08:52,350
And whatever value you are getting, you are just likely returning.

129
00:08:52,580 --> 00:08:55,270
So I am returning one and one is the right answer.

130
00:08:56,590 --> 00:08:57,100
Simple.

131
00:08:57,880 --> 00:09:01,180
So basically, what is happening, this is your ready.

132
00:09:02,680 --> 00:09:06,220
This is a value of zero you are checking.

133
00:09:07,160 --> 00:09:13,150
Whether X is correct position at this position or not, if it is not present, then you are moving ahead.

134
00:09:13,460 --> 00:09:14,750
So then we are moving ahead.

135
00:09:14,930 --> 00:09:16,760
So we are checking at this position.

136
00:09:16,760 --> 00:09:17,830
X is present or not.

137
00:09:18,050 --> 00:09:19,910
If it is present, you will return.

138
00:09:20,460 --> 00:09:22,460
If it is present, you will return the value of it.

139
00:09:22,760 --> 00:09:29,480
If it is not present, you are moving ahead and then you are again checking if if present return otherwise

140
00:09:29,480 --> 00:09:30,080
movahed.

141
00:09:31,410 --> 00:09:36,000
So similarly, if the X is not present inside the area, so you will reach here.

142
00:09:37,990 --> 00:09:43,710
And so if you're Richard Nixon, you will return minus one, so we will return minus one value not found

143
00:09:43,990 --> 00:09:44,530
simple.

144
00:09:46,290 --> 00:09:47,740
So this is it from this video.

145
00:09:47,790 --> 00:09:49,080
I will see you in the next one.

