1
00:00:01,650 --> 00:00:02,370
Hi, everyone.

2
00:00:02,400 --> 00:00:07,020
So in this video, we are going to solve this question, Jack, palindrome, and we need to solve this

3
00:00:07,020 --> 00:00:08,189
question using recursion.

4
00:00:08,490 --> 00:00:13,740
So you know what this palindrome palindrome is, if you will read from left to right or if you read

5
00:00:13,740 --> 00:00:18,300
from right to left, they will be equal, for example, one, two and one.

6
00:00:19,110 --> 00:00:22,080
So read from left to right or from right to left.

7
00:00:22,450 --> 00:00:28,080
They are saying so one, one, three, three, two and two.

8
00:00:28,290 --> 00:00:29,670
So read from left to right.

9
00:00:29,670 --> 00:00:31,110
One, three, two, two, three, one.

10
00:00:31,230 --> 00:00:32,580
And read from right to left.

11
00:00:32,790 --> 00:00:34,430
One, three, two, two, three, one.

12
00:00:34,740 --> 00:00:36,450
So this is a palindrome.

13
00:00:37,460 --> 00:00:39,020
This is also a palindrome.

14
00:00:40,580 --> 00:00:41,430
One, two, three.

15
00:00:41,480 --> 00:00:43,250
This is not a palindrome from left to right.

16
00:00:43,280 --> 00:00:44,180
It is one, two, three.

17
00:00:44,180 --> 00:00:45,910
From right to left, it is three to one.

18
00:00:46,250 --> 00:00:47,810
So this is not a palindrome.

19
00:00:49,050 --> 00:00:54,990
You have to write a function, they're able to function flyball, so you have to tell whether it is

20
00:00:54,990 --> 00:00:56,550
a palindrome or not, so it will return.

21
00:00:56,550 --> 00:00:57,280
True or false?

22
00:00:58,380 --> 00:01:00,980
The name of the function, let's a palindrome.

23
00:01:02,100 --> 00:01:06,870
It will take ideas and put it will take starting next and the next.

24
00:01:09,070 --> 00:01:13,570
So we need to solve this question using an equation, so how against all this question?

25
00:01:13,600 --> 00:01:14,530
So it's very simple.

26
00:01:14,560 --> 00:01:15,340
This is already.

27
00:01:16,720 --> 00:01:22,540
So I'm giving it I'm giving the starting next, I'm giving the end index, so this is the start index

28
00:01:23,020 --> 00:01:23,880
initially zero.

29
00:01:24,910 --> 00:01:28,240
This is the index which is initially and minus one.

30
00:01:28,690 --> 00:01:30,200
So first of all, I will check.

31
00:01:30,460 --> 00:01:32,440
So these two elements should be same.

32
00:01:33,990 --> 00:01:40,890
So if these two elements have seem so, if this element and this element are same, then my work is

33
00:01:40,890 --> 00:01:46,410
done, I will call occasion for Destry, I will call for this very simple.

34
00:01:46,710 --> 00:01:51,110
So Rákosi will give me where this small area is palindrome or very small.

35
00:01:51,110 --> 00:01:51,120
Small.

36
00:01:51,240 --> 00:01:52,230
It is not palindrome.

37
00:01:53,100 --> 00:01:56,820
And simultaneously, if this is my last palindrome, I will return.

38
00:01:56,820 --> 00:02:02,190
True, if this small area is not palindrome, then the bigger will also not be a palindrome.

39
00:02:02,460 --> 00:02:07,710
OK, so if the smaller is palindrome, then bigger is also palindrome because we already checked for

40
00:02:07,710 --> 00:02:08,550
these two elements.

41
00:02:09,009 --> 00:02:09,470
Right?

42
00:02:09,960 --> 00:02:11,550
So let's rewrite the code.

43
00:02:15,430 --> 00:02:18,660
So, Intisar, not in danger.

44
00:02:18,720 --> 00:02:19,480
There will be.

45
00:02:21,570 --> 00:02:23,920
The name of the function is Jack Palindrome.

46
00:02:24,630 --> 00:02:28,590
I will take areas and but you can take a digit area.

47
00:02:28,590 --> 00:02:29,370
You can correct.

48
00:02:29,580 --> 00:02:30,390
It's your choice.

49
00:02:31,200 --> 00:02:32,920
I will take this starting next.

50
00:02:32,940 --> 00:02:35,030
I will take the ending, Alex.

51
00:02:37,330 --> 00:02:44,080
So first of all, the base case, what is the base case, so base cases, if it is empty, see if it

52
00:02:44,080 --> 00:02:51,280
is empty, if it does not exist, so if it does not exist, in normal case, START is here and is here.

53
00:02:51,310 --> 00:02:58,210
So in normal case, status, Lieutenant, in normal situation, but if the area is empty, then start

54
00:02:58,210 --> 00:02:58,750
will be cleared.

55
00:02:58,810 --> 00:03:00,460
And if that is empty.

56
00:03:02,090 --> 00:03:10,850
So if that is and start is going to end, so in that case, I will return to empty, it is a palindrome.

57
00:03:12,710 --> 00:03:17,030
If that is empty and yet it is said to be a palindrome.

58
00:03:17,060 --> 00:03:19,630
OK, so empty, it is a palindrome.

59
00:03:20,000 --> 00:03:21,320
Otherwise what we need to do.

60
00:03:22,550 --> 00:03:25,510
So what we need to do, this is our very.

61
00:03:27,070 --> 00:03:30,070
So this is the starting starting next.

62
00:03:30,100 --> 00:03:35,170
This is the end, the next and then what I have to do, I have to compare these two values.

63
00:03:37,290 --> 00:03:42,780
So if these two values are equal start and they are equal, I will call that equation for this small

64
00:03:42,780 --> 00:03:44,760
area, otherwise I will return false.

65
00:03:46,620 --> 00:03:53,550
It is very simple if the start value and the end value, so if they are equal.

66
00:03:55,280 --> 00:03:59,900
I will call Dacogen, so I will do something in the aspart.

67
00:04:01,520 --> 00:04:06,590
I will return false if they are not equal, so if they are not equal, I will return false.

68
00:04:06,620 --> 00:04:08,060
Otherwise I will do something.

69
00:04:08,390 --> 00:04:11,300
And what I will do so I will collocation.

70
00:04:12,490 --> 00:04:14,260
I will call occasion for deciding.

71
00:04:17,649 --> 00:04:21,350
So the equation will tell me whether this is a palindrome or not.

72
00:04:21,550 --> 00:04:24,700
So if this area is not palindrome, so the question will return false.

73
00:04:24,940 --> 00:04:28,350
So if the smaller is not, then bigger, it is also not palindrome.

74
00:04:28,600 --> 00:04:29,990
So I will likely return false.

75
00:04:30,220 --> 00:04:30,780
So I have this.

76
00:04:30,790 --> 00:04:33,400
Mollari is a palindrome, so the question will return.

77
00:04:33,400 --> 00:04:33,650
True.

78
00:04:33,880 --> 00:04:39,250
So if this is palindrome and I already checked that these two elements are also equal, so bigger is

79
00:04:39,250 --> 00:04:39,980
also a palindrome.

80
00:04:40,000 --> 00:04:40,660
So I will return.

81
00:04:40,660 --> 00:04:40,910
True.

82
00:04:41,140 --> 00:04:45,100
So whatever the result recursion is giving me, I am directly returning that result.

83
00:04:45,290 --> 00:04:49,050
OK, so if it's true, I will return to Africa.

84
00:04:49,370 --> 00:04:51,250
That's what I will return false.

85
00:04:52,060 --> 00:04:56,950
So I just need to return the value which recursion is returning me.

86
00:04:57,160 --> 00:04:58,480
So how we can call for this.

87
00:04:58,960 --> 00:05:02,050
So for this idea, this is the starting index.

88
00:05:02,680 --> 00:05:04,860
This is the starting next for this small area.

89
00:05:04,870 --> 00:05:07,960
And this is the ending index for the small area.

90
00:05:07,990 --> 00:05:12,940
So starting indexes basically start plus one and then index is basically and minus one.

91
00:05:14,480 --> 00:05:15,350
So let's call.

92
00:05:16,520 --> 00:05:26,450
So I need to check whether the small arrest or not I will pass so far small at the the next is a start

93
00:05:26,450 --> 00:05:32,180
plus one for the small at the end being next is and the minus one and minus one.

94
00:05:32,780 --> 00:05:37,160
And whatever the result this function will give, it will return it to Werfel's value.

95
00:05:37,400 --> 00:05:39,420
So I will likely return that value.

96
00:05:40,160 --> 00:05:43,580
So let's create one error here in Digerati.

97
00:05:43,580 --> 00:05:43,580
Ready.

98
00:05:46,020 --> 00:05:52,610
So let's say the first element is one, two, three, then again, three, two and one.

99
00:05:52,980 --> 00:05:54,140
So this is a palindrome.

100
00:05:54,540 --> 00:05:57,750
Let's call the function called palindrome.

101
00:06:03,090 --> 00:06:04,540
Starting next is zero.

102
00:06:05,100 --> 00:06:10,980
What is the last index, so the sizes is one, two, three, four, five and six sizes, six elements

103
00:06:10,980 --> 00:06:11,430
is six.

104
00:06:11,450 --> 00:06:12,750
So the last Nexus five.

105
00:06:14,380 --> 00:06:21,460
So I am calling the function room six, so starting next to zero and the next is basically and minus

106
00:06:21,460 --> 00:06:22,780
one, which is six.

107
00:06:22,780 --> 00:06:24,080
Minus one, that is five.

108
00:06:25,060 --> 00:06:27,370
So this check function will return to.

109
00:06:28,590 --> 00:06:36,240
And I am painting so true, this one will be printed if it returns false, false, zero printed since

110
00:06:36,240 --> 00:06:38,460
this is a palindrome, so the output will be one.

111
00:06:41,410 --> 00:06:42,460
So output will be one.

112
00:06:43,810 --> 00:06:49,720
Harpreet is coming out driven because it is a palindrome, and for example, if it is Ford, let's make

113
00:06:49,720 --> 00:06:50,110
it Ford.

114
00:06:50,530 --> 00:06:51,970
So now this is not a palindrome.

115
00:06:51,970 --> 00:06:53,020
So output will be zero.

116
00:06:54,550 --> 00:06:59,040
So our party's coming out with zero simple, let's take one more case.

117
00:07:00,460 --> 00:07:07,990
So this is basically the even number of elements, let's take a number of elements commentary and the

118
00:07:07,990 --> 00:07:09,750
last index will now be six now.

119
00:07:10,150 --> 00:07:11,530
So this is a palindrome.

120
00:07:11,560 --> 00:07:13,230
OK, this is a palindrome.

121
00:07:13,780 --> 00:07:18,160
One, two, three, four, three, two, and one.

122
00:07:18,520 --> 00:07:21,400
So read from left to right or from right to left.

123
00:07:21,620 --> 00:07:22,610
It is a palindrome.

124
00:07:22,840 --> 00:07:24,480
So this is the starting next zero.

125
00:07:24,490 --> 00:07:28,100
This is the ending index, which is six because the total number of elements is seven.

126
00:07:28,450 --> 00:07:30,380
So output will be one through.

127
00:07:30,730 --> 00:07:33,580
So one minister, this is a palindrome.

128
00:07:33,590 --> 00:07:34,900
That's why I am getting one.

129
00:07:36,800 --> 00:07:40,110
So that's how everything is working, so let's try in one example.

130
00:07:40,160 --> 00:07:41,390
So let's take one example.

131
00:07:41,430 --> 00:07:41,910
Right.

132
00:07:42,800 --> 00:07:44,170
So let's take this example.

133
00:07:44,960 --> 00:07:45,650
I have one.

134
00:07:46,590 --> 00:07:50,650
So two, three, four, three, two and one.

135
00:07:51,570 --> 00:07:52,860
So this is the start.

136
00:07:53,550 --> 00:07:54,540
This is the end.

137
00:07:56,070 --> 00:08:01,350
Kick start the article, so start and the article, so call on this, Mollari.

138
00:08:02,730 --> 00:08:10,610
So this is already it is containing all the elements one, two, three, four, three, two and one.

139
00:08:11,760 --> 00:08:13,380
So this is us start.

140
00:08:13,560 --> 00:08:14,940
You are doing start plus one.

141
00:08:15,120 --> 00:08:16,500
OK, start will move ahead.

142
00:08:16,920 --> 00:08:19,320
You are doing an A minus one so and will move back.

143
00:08:19,320 --> 00:08:21,180
So this is your end now check.

144
00:08:21,570 --> 00:08:23,360
So start and they are equal.

145
00:08:23,370 --> 00:08:26,030
So if they are equal, call on this Mollari.

146
00:08:27,150 --> 00:08:34,620
So this is already the elements are one, two, three, four, three, two.

147
00:08:34,620 --> 00:08:38,460
And when we are passing the completely OK we are passing completed.

148
00:08:39,210 --> 00:08:41,100
So this is our start.

149
00:08:41,100 --> 00:08:46,380
This is our start and this is our end start plus one and minus one.

150
00:08:46,380 --> 00:08:49,330
OK, start listening to minus one, check three three.

151
00:08:49,350 --> 00:08:52,110
They are same so three and three the same.

152
00:08:52,290 --> 00:08:54,180
So again collocation on this merletti.

153
00:08:56,010 --> 00:08:57,090
So colocation.

154
00:08:58,410 --> 00:09:02,360
We are passing the completely we are just changing the starting point, the.

155
00:09:04,380 --> 00:09:13,880
So start plus one and a minus one and minus one, so start here and is here, so four is equal to four.

156
00:09:14,280 --> 00:09:16,880
So I will call again on the three.

157
00:09:17,190 --> 00:09:18,450
So I'm calling again on the.

158
00:09:20,090 --> 00:09:25,340
The elements are one, two, three, four, three, two and one.

159
00:09:26,270 --> 00:09:29,790
So START will move ahead and will move back.

160
00:09:29,810 --> 00:09:36,200
So we start this here and here, you can see start plus one and minus one.

161
00:09:36,380 --> 00:09:37,910
So start will move.

162
00:09:39,150 --> 00:09:43,050
Forward and will move backward, so now we will hit the best case.

163
00:09:43,080 --> 00:09:44,130
So what is the best case?

164
00:09:44,130 --> 00:09:47,820
Start is bigger than any, so start is now bigger than that.

165
00:09:47,850 --> 00:09:49,710
So in that case, I will return to.

166
00:09:50,040 --> 00:09:51,150
I will return to.

167
00:09:52,520 --> 00:09:57,350
And you can see whatever value we're getting from because we are directly returning, so I will return

168
00:09:57,350 --> 00:09:57,640
true.

169
00:09:57,650 --> 00:09:59,560
I will return true, I will return true.

170
00:09:59,570 --> 00:10:00,480
I will return true.

171
00:10:01,220 --> 00:10:03,050
So this is a palindrome.

172
00:10:03,050 --> 00:10:03,890
I am getting through.

173
00:10:03,890 --> 00:10:04,800
I will print one.

174
00:10:05,630 --> 00:10:06,830
So let's take one example.

175
00:10:06,830 --> 00:10:12,020
When this is not a palindrome, when this is not a palindrome, let's take that example.

176
00:10:12,260 --> 00:10:14,510
So this is one, two, three.

177
00:10:15,020 --> 00:10:17,300
I have four, then two and then one.

178
00:10:17,630 --> 00:10:19,050
So this is not a palindrome.

179
00:10:19,430 --> 00:10:20,400
This is the start.

180
00:10:20,570 --> 00:10:22,670
This is the end start.

181
00:10:22,670 --> 00:10:23,900
And they are equal.

182
00:10:24,290 --> 00:10:30,600
So called recursion and bosnich complete and update the value of starting.

183
00:10:30,620 --> 00:10:35,680
And so start plus and minus and start will come here and will come here.

184
00:10:36,230 --> 00:10:37,360
This is a start.

185
00:10:37,370 --> 00:10:39,830
This is and compared to the two.

186
00:10:40,460 --> 00:10:43,190
So they are equal collocation.

187
00:10:44,630 --> 00:10:50,600
If they are equal we will call recursion and it will pass the computer, we will pass the whole array

188
00:10:50,600 --> 00:10:52,730
and we will change the values of starting in.

189
00:10:53,770 --> 00:10:57,280
So START will move ahead and will move back.

190
00:10:57,310 --> 00:11:00,210
So this is your start, this is your end.

191
00:11:00,850 --> 00:11:05,820
So now you can see start and end the article, so you will return false.

192
00:11:05,830 --> 00:11:07,960
You will go in the spot and you will return false.

193
00:11:08,350 --> 00:11:09,790
So you will return false.

194
00:11:11,870 --> 00:11:18,740
So basically for this very dirty question we are getting for this area, basically that equation is

195
00:11:18,740 --> 00:11:19,580
returning false.

196
00:11:19,790 --> 00:11:21,500
OK, that equation is giving me false.

197
00:11:21,830 --> 00:11:23,510
So the equation is giving false.

198
00:11:23,720 --> 00:11:26,660
So whatever value you're getting from the equation, you are likely returning.

199
00:11:26,690 --> 00:11:30,680
So I will return false and I will return false.

200
00:11:32,210 --> 00:11:34,570
So for false, I will print zero.

201
00:11:35,000 --> 00:11:37,510
So that's why zero printed for this area.

202
00:11:39,330 --> 00:11:40,870
So I hope you understood this question.

203
00:11:41,910 --> 00:11:43,440
So this is it from this video.

204
00:11:43,710 --> 00:11:45,020
I will see you in the next one.

205
00:11:45,720 --> 00:11:45,930
Bye.

