1
00:00:01,760 --> 00:00:02,450
Hi, everyone.

2
00:00:02,480 --> 00:00:07,280
So today we are going to sign the revised version of the problem that we saw in the earlier session,

3
00:00:07,670 --> 00:00:08,760
so cycle two.

4
00:00:09,140 --> 00:00:13,700
Now, in this problem, what we have to do, so instead of returning a boolean value, we have to return.

5
00:00:14,850 --> 00:00:16,390
The starting point of the loop.

6
00:00:16,410 --> 00:00:19,470
OK, so we have to return to here in the last problem.

7
00:00:19,500 --> 00:00:21,210
We have to return only to our fault.

8
00:00:21,510 --> 00:00:25,770
But in this problem, we have to return the starting point of the loop.

9
00:00:26,040 --> 00:00:28,630
So the starting point of the loop is to OK.

10
00:00:28,930 --> 00:00:32,460
So so this question is present on the record.

11
00:00:32,860 --> 00:00:38,610
OK, so for example, here, the starting point is to set out what should we do here?

12
00:00:38,610 --> 00:00:40,830
The starting point is one or at least the output is one.

13
00:00:40,830 --> 00:00:43,550
And here there is no cycle.

14
00:00:43,560 --> 00:00:45,180
So I will return null.

15
00:00:45,420 --> 00:00:49,920
OK, and our challenge is to solve this problem without using any extra space.

16
00:00:50,700 --> 00:00:51,120
OK.

17
00:00:53,320 --> 00:00:55,150
So this was our only problem.

18
00:00:56,440 --> 00:01:01,090
Now, how we can solve this problem, so the first approach of solving this problem is with the help

19
00:01:01,090 --> 00:01:01,690
of MAP.

20
00:01:04,379 --> 00:01:10,200
OK, we can solve this problem easily with the help of map, just like in the old session, just like

21
00:01:10,200 --> 00:01:14,670
in the earlier session, what we will do, we will take a map of Little North Star and value.

22
00:01:15,030 --> 00:01:20,330
So I will take a map of list North Star and a Boolean value.

23
00:01:20,550 --> 00:01:21,400
So what we will do.

24
00:01:22,350 --> 00:01:24,350
OK, so let's do this problem.

25
00:01:24,360 --> 00:01:26,520
So I have a map, eight percent inside the map.

26
00:01:26,520 --> 00:01:30,570
No one present, no more than nine percent inside the map.

27
00:01:30,580 --> 00:01:30,760
No.

28
00:01:30,840 --> 00:01:32,820
Then Bush for president.

29
00:01:32,820 --> 00:01:33,170
No.

30
00:01:33,180 --> 00:01:34,830
Then put forward to present.

31
00:01:34,830 --> 00:01:38,280
No, but to three percent or seven percent.

32
00:01:38,280 --> 00:01:39,420
No to president no.

33
00:01:39,420 --> 00:01:39,990
Nine percent.

34
00:01:39,990 --> 00:01:40,210
No.

35
00:01:40,230 --> 00:01:41,400
So put all of these.

36
00:01:41,400 --> 00:01:45,150
So three, seven, two and nine.

37
00:01:45,390 --> 00:01:48,690
Then again is to present inside the maps to is present.

38
00:01:48,900 --> 00:01:52,260
So in the only problem would be did the return to at this point.

39
00:01:52,260 --> 00:02:00,060
But here what we will do, we will return to OK, we have I will return my key value, I will simply

40
00:02:00,060 --> 00:02:01,770
return to the time.

41
00:02:01,770 --> 00:02:05,550
Complexity is basically when and the space complexity is on.

42
00:02:05,680 --> 00:02:07,380
OK, so let us implement.

43
00:02:08,289 --> 00:02:11,280
OK, so I closed the solution.

44
00:02:13,790 --> 00:02:20,660
So I will copy the same code just instead of returning the troops, instead of returning to enforce

45
00:02:20,660 --> 00:02:21,640
what they've done.

46
00:02:23,660 --> 00:02:25,490
We will them better than they normally do.

47
00:02:26,180 --> 00:02:29,990
OK, let's make this a.

48
00:02:31,340 --> 00:02:37,070
So instead of returning the true what they will return, I will return, OK, instead of returning false

49
00:02:37,070 --> 00:02:38,040
here, I will return.

50
00:02:40,490 --> 00:02:40,940
OK.

51
00:02:42,380 --> 00:02:44,180
So let's try to separate the so-called.

52
00:02:47,700 --> 00:02:52,010
OK, so our goal is working, so their time in the space complexities both our own.

53
00:02:52,440 --> 00:02:54,270
OK, so can we do better?

54
00:02:54,300 --> 00:02:55,830
Yes, obviously we can do better.

55
00:02:56,130 --> 00:02:58,410
So how we can solve this problem.

56
00:02:58,560 --> 00:03:03,900
So in the earlier session, we we discussed about the floor and the first point, that approach.

57
00:03:03,930 --> 00:03:06,460
OK, so how we can use this law enforcement approach.

58
00:03:06,720 --> 00:03:12,510
So if you remember the legislation both and slow and fast point that approach made at this point.

59
00:03:12,660 --> 00:03:17,620
OK, so both slow and fast point approach, they were meeting at this point.

60
00:03:17,880 --> 00:03:21,880
So after meeting at this point, what I will do, I will find the size of the loop.

61
00:03:21,900 --> 00:03:26,670
OK, so find the size of the loop to her finding the size of the loop.

62
00:03:26,760 --> 00:03:28,490
What what can I do here?

63
00:03:28,800 --> 00:03:35,610
So keep one pointer at three, for example, keep fast pointed at three and move the slow pointer.

64
00:03:35,640 --> 00:03:41,010
OK, so it's lowpoint that will move so slow will come here then slow will come here, then slow will

65
00:03:41,010 --> 00:03:44,700
come here, then snow will come here and then slow will again.

66
00:03:44,700 --> 00:03:45,210
Come here.

67
00:03:45,290 --> 00:03:52,320
OK, so while the slow pointer is moving around, what I will do, I will maintain account and I will

68
00:03:52,320 --> 00:03:53,360
do current placeless.

69
00:03:53,610 --> 00:03:58,260
So when the slope in the first point I will meet again, I will get to know the size of the loop.

70
00:03:58,560 --> 00:04:02,680
OK, so once we know the size of the loop, so let's say the size of the loop.

71
00:04:02,700 --> 00:04:05,080
So here, one, two, three, four and five.

72
00:04:05,100 --> 00:04:07,080
So this is the loop will come out to be five.

73
00:04:07,380 --> 00:04:10,420
OK, so we'll say slope point will come here.

74
00:04:10,440 --> 00:04:15,120
So card will become one, then two, then three, then the will of current forward and then the value

75
00:04:15,120 --> 00:04:16,240
of count will become five.

76
00:04:16,740 --> 00:04:19,740
So we will get to know the size of the loop easily.

77
00:04:19,740 --> 00:04:20,440
Very easily.

78
00:04:20,510 --> 00:04:24,840
OK, so once we know the size of the law, what we can do, we will take two point.

79
00:04:24,990 --> 00:04:27,000
Again, we will take.

80
00:04:27,950 --> 00:04:32,380
Two points again, so I will keep the first pointer here.

81
00:04:33,420 --> 00:04:38,790
And what I will do with the second pointer to the second point, I will move five steps ahead.

82
00:04:39,060 --> 00:04:44,830
So step one, step two, step three, step forward and step five.

83
00:04:45,090 --> 00:04:47,070
So this will be my second pointer.

84
00:04:47,430 --> 00:04:52,380
And then both first and second point, they will move at the same speed.

85
00:04:52,380 --> 00:04:54,210
They will take one jump at a time.

86
00:04:54,530 --> 00:04:56,670
OK, they will take one jump at a time.

87
00:04:56,970 --> 00:05:00,870
So first comes here and second comes here.

88
00:05:01,410 --> 00:05:02,640
First comes here.

89
00:05:03,000 --> 00:05:04,230
Second comes here.

90
00:05:04,620 --> 00:05:05,850
First comes here.

91
00:05:06,090 --> 00:05:07,320
Second comes here.

92
00:05:07,560 --> 00:05:08,700
First comes here.

93
00:05:08,700 --> 00:05:10,200
And second also comes here.

94
00:05:10,710 --> 00:05:15,210
OK, both first and second will meet only at the starting point.

95
00:05:15,480 --> 00:05:20,790
OK, so both first and second pointer, they will meet only at the starting point.

96
00:05:21,150 --> 00:05:22,320
Why starting point.

97
00:05:22,440 --> 00:05:27,720
Because the difference between the second pointer and second pointer minus first point, the difference

98
00:05:27,720 --> 00:05:32,190
between them is basically key and what is fake is basically the size of the loop.

99
00:05:33,390 --> 00:05:39,000
OK, guys, basically the size of the loop, so the only point we had, the first and the second point

100
00:05:39,000 --> 00:05:41,490
I can meet is basically the starting point.

101
00:05:42,210 --> 00:05:44,400
They can they cannot meet anywhere else.

102
00:05:44,680 --> 00:05:50,380
OK, so with the help of this approach, our time will be open and our space will be open.

103
00:05:50,730 --> 00:05:52,280
OK, and this was the challenge.

104
00:05:52,680 --> 00:05:54,330
So in order to write the code.

105
00:05:56,200 --> 00:05:58,730
OK, so far, so what we will do.

106
00:05:58,750 --> 00:06:00,340
We will copy this code also.

107
00:06:04,720 --> 00:06:06,220
Slow and fast pointer approach.

108
00:06:10,160 --> 00:06:13,580
OK, so let's comment about this map approach.

109
00:06:20,600 --> 00:06:23,190
OK, so here we will not return anything, but we will do.

110
00:06:23,210 --> 00:06:25,480
We will only break this loop, OK?

111
00:06:25,850 --> 00:06:31,220
We will only break this loop and this means there is basically cycle cycle addicted.

112
00:06:33,310 --> 00:06:35,080
OK, so the cyclist predicted.

113
00:06:37,370 --> 00:06:44,600
Now, if there is not any cycle, if the cycle is not there, basically if the forest becomes null.

114
00:06:44,680 --> 00:06:51,950
OK, so if the fastest null light means cycle does not exist or we can see the next.

115
00:06:54,340 --> 00:06:58,080
The next of fast becomes then also cycle does not exist.

116
00:07:00,750 --> 00:07:02,670
So if this is the case, that means.

117
00:07:03,920 --> 00:07:10,940
Cycle does not exist, so if the cycle does not exist, we can simply eternal, OK, so there are two

118
00:07:10,940 --> 00:07:12,780
ways to come out of this loop.

119
00:07:12,980 --> 00:07:17,260
First is due to the big statement, that means the news cycle cycle is dead.

120
00:07:17,450 --> 00:07:20,460
Second is with the help of this condition, if this condition becomes false.

121
00:07:20,690 --> 00:07:24,580
So if the condition becomes false, that means there is no cycle.

122
00:07:24,590 --> 00:07:26,710
So I'm returning null, OK?

123
00:07:28,660 --> 00:07:35,860
Now, as discussed, so what we have to do, so I am summarizing the points, what we have to do, we

124
00:07:35,860 --> 00:07:38,160
have to first find the size of the loop.

125
00:07:39,070 --> 00:07:41,560
We have to first find the size of this cycle.

126
00:07:41,820 --> 00:07:43,530
OK, so we're finding the size.

127
00:07:43,540 --> 00:07:49,600
What we do, we will keep the first point where it is and we will move this little pointer around.

128
00:07:50,500 --> 00:07:55,970
And while this low point does meet is moving around, I will maintain the count, OK?

129
00:07:55,990 --> 00:07:59,950
Once we get the count, but we have to do we have to, again, take two pointers.

130
00:08:00,460 --> 00:08:03,400
Both the pointers will be present at the end of the list.

131
00:08:03,730 --> 00:08:06,610
So first pointer and the second pointer will move.

132
00:08:06,610 --> 00:08:09,340
Tekin Pointer count steps ahead.

133
00:08:09,370 --> 00:08:11,350
OK, so count will move.

134
00:08:11,350 --> 00:08:13,070
The second point, the count step ahead.

135
00:08:13,300 --> 00:08:19,870
Now the difference between the second and the first pointer is basically key now both the first and

136
00:08:19,870 --> 00:08:25,780
the second point that they will move at the same speed, OK, they will move at the same speed and the

137
00:08:25,780 --> 00:08:30,460
only point where they can intersect, where they can meet is the starting point of the linked list.

138
00:08:30,610 --> 00:08:35,390
OK, because the difference between them is gay and basically the size of the loop.

139
00:08:35,890 --> 00:08:38,360
OK, so I hope that makes sense to you.

140
00:08:39,640 --> 00:08:42,700
So now let us try to find the size of the loop.

141
00:08:46,620 --> 00:08:47,460
OK, so.

142
00:08:49,640 --> 00:08:55,190
Let's move slow point to one step ahead, so slow because the next Oslo.

143
00:08:58,480 --> 00:09:01,140
OK, and gay kwasman, OK?

144
00:09:02,270 --> 00:09:04,490
Now, while slow, is not close to fast.

145
00:09:08,010 --> 00:09:14,580
But we have to do so slow will move around slow equals next slow.

146
00:09:17,880 --> 00:09:22,780
And we will look, C++ is basically the number of nodes present inside the loop.

147
00:09:22,810 --> 00:09:28,660
OK, now at this point, we know the size of the loop, so I have to take two pointers here.

148
00:09:28,740 --> 00:09:29,100
OK.

149
00:09:30,510 --> 00:09:31,650
So I have to take.

150
00:09:33,040 --> 00:09:37,830
Two pointers, one and two, so they both will be present at the head of the linked list.

151
00:09:37,930 --> 00:09:40,890
OK, they're both fully present at the head of the list.

152
00:09:42,150 --> 00:09:43,280
The second point, the.

153
00:09:45,740 --> 00:09:50,000
Now, what we have to do is move the second point, 30 steps ahead.

154
00:09:50,030 --> 00:09:51,500
OK, so.

155
00:09:55,230 --> 00:09:55,800
Move.

156
00:09:57,310 --> 00:09:59,680
Second point steps ahead.

157
00:10:04,640 --> 00:10:06,800
OK, so while K minus minus.

158
00:10:10,410 --> 00:10:11,820
To is next to.

159
00:10:14,410 --> 00:10:18,650
OK, now what we have to do now move both the point that at the same speed.

160
00:10:18,710 --> 00:10:23,980
OK, so move both first and second pointer at the same speed.

161
00:10:23,990 --> 00:10:27,010
So move both pointer at the same speed.

162
00:10:29,860 --> 00:10:38,410
And they will only intersect at the starting point, so while one is not equal to two.

163
00:10:40,620 --> 00:10:45,120
So what we have to do seems beautiful when it goes the next of one.

164
00:10:46,730 --> 00:10:48,860
And two equals.

165
00:10:50,570 --> 00:10:51,380
Next of the.

166
00:10:52,680 --> 00:10:55,650
OK, so I think our gold is fine and it should work.

167
00:10:57,050 --> 00:11:03,320
OK, so once this loop is over, you can return one or you can return to, OK, I can return one or

168
00:11:03,320 --> 00:11:04,430
I can return to.

169
00:11:21,420 --> 00:11:22,890
OK, so our court is working.

170
00:11:25,900 --> 00:11:31,540
OK, so Al Gore is working now, the time and the space complexity of the solution is time is on and

171
00:11:31,540 --> 00:11:33,880
the space is big of one.

172
00:11:34,070 --> 00:11:37,390
OK, now there is easier way to solve this problem.

173
00:11:37,420 --> 00:11:41,640
OK, we have discussed we have discussed a solution for this problem.

174
00:11:41,650 --> 00:11:45,350
Now there exists a third solution, which is the most optimized solution.

175
00:11:45,370 --> 00:11:49,950
OK, now we will use the floor in the Fassbinder approach.

176
00:11:50,260 --> 00:11:54,740
So if we remember both slow and fast, Pointer will meet here.

177
00:11:54,830 --> 00:12:00,800
OK, so this lowpoint, those here and first point is here now after this low point in the first point,

178
00:12:00,800 --> 00:12:01,300
that approach.

179
00:12:01,810 --> 00:12:02,710
But we have to do.

180
00:12:04,420 --> 00:12:08,230
Move this little pointer at the head of the linked list again.

181
00:12:08,290 --> 00:12:10,510
OK, so remove the slow pointer from here.

182
00:12:12,150 --> 00:12:14,250
And put this low point guard here.

183
00:12:15,880 --> 00:12:22,480
OK, so the first step is move slow pointer to head.

184
00:12:24,580 --> 00:12:34,690
OK, now the second is what will do both slow and fast, move both slow and fast at the same speed?

185
00:12:36,800 --> 00:12:39,200
Move both slow and fast at the same speed.

186
00:12:39,230 --> 00:12:40,070
So what will happen?

187
00:12:41,400 --> 00:12:46,560
So after moving slow and fast, slow will come here.

188
00:12:47,760 --> 00:12:48,930
Fosterville, come here.

189
00:12:50,900 --> 00:12:51,980
Slow welcome here.

190
00:12:53,610 --> 00:12:54,720
Fosterville, come here.

191
00:12:56,730 --> 00:12:57,780
Slow welcome, come here.

192
00:13:00,630 --> 00:13:01,800
Fosterville, come here.

193
00:13:03,580 --> 00:13:04,630
Slow welcome here.

194
00:13:06,220 --> 00:13:12,430
And Fosterville, come here so you can see both slow and fast will meet at the starting point.

195
00:13:12,600 --> 00:13:15,700
OK, so what we have to do, we have to only take two steps.

196
00:13:15,700 --> 00:13:18,070
First, move the slow to the head.

197
00:13:19,210 --> 00:13:24,430
And then move slow and fast at the same speed, and they will intersect at the starting point of the

198
00:13:24,430 --> 00:13:24,700
loop.

199
00:13:25,150 --> 00:13:26,700
Now, why this is the scenario.

200
00:13:27,160 --> 00:13:29,620
So this is very simple mathematical problem.

201
00:13:30,040 --> 00:13:33,580
So first, let us write the code and then we will explain the mathematical solution.

202
00:13:34,030 --> 00:13:34,450
OK.

203
00:13:37,290 --> 00:13:38,880
So let us come out discord.

204
00:13:49,430 --> 00:13:50,720
So what we are doing here?

205
00:13:52,040 --> 00:13:54,830
So this is a simple solution, Fassbinder approach.

206
00:13:55,190 --> 00:13:59,990
OK, so once this low point and the first point I approach, what we have to do is move slow to the

207
00:13:59,990 --> 00:14:00,290
head.

208
00:14:00,440 --> 00:14:03,590
OK, so we have to do two steps.

209
00:14:04,280 --> 00:14:11,000
So the first step is move slow to the head and then move slow and fast at the same speed.

210
00:14:11,540 --> 00:14:11,960
OK.

211
00:14:13,720 --> 00:14:20,980
So move slow to the head, so slow it was a now slow is they're tired and they will only intersect.

212
00:14:22,610 --> 00:14:26,000
At this starting point, so while slow is not too fast.

213
00:14:27,520 --> 00:14:30,880
We have to move them, and this means we at the same speed, OK?

214
00:14:38,940 --> 00:14:43,100
Simple, and you can read Denslow or you can read them first.

215
00:14:43,240 --> 00:14:43,620
OK.

216
00:14:49,210 --> 00:14:55,030
OK, so our goal is working now, we have to write only this much code and we will get the starting

217
00:14:55,030 --> 00:14:56,020
point of the linked list.

218
00:14:56,110 --> 00:14:57,680
Now, how this is working.

219
00:14:57,700 --> 00:14:58,790
Let us try to understand.

220
00:14:59,250 --> 00:15:00,850
OK, so.

221
00:15:04,000 --> 00:15:04,840
So suppose.

222
00:15:07,860 --> 00:15:10,680
This is the cycle in the linked list.

223
00:15:10,710 --> 00:15:13,570
OK, and let's take some variables.

224
00:15:13,590 --> 00:15:21,630
So suppose this is this dense M and let's say this is Mr. Mansky.

225
00:15:22,560 --> 00:15:25,440
And so this is my intersection.

226
00:15:25,470 --> 00:15:31,330
This is basically the starting point of the linked list and this is the point where slow and fast intersect.

227
00:15:31,780 --> 00:15:34,320
OK, initially slow and fast intersect here.

228
00:15:34,680 --> 00:15:43,600
And let's say the size of the slope, the size of this loop is basically let's call it El, OK?

229
00:15:43,950 --> 00:15:49,050
Now, initially, so before meeting at this point, slow and fast pointer.

230
00:15:49,380 --> 00:15:52,260
So how many distance slow points will cover.

231
00:15:52,710 --> 00:15:55,950
So distance traveled by small point.

232
00:15:55,950 --> 00:15:58,140
That is basically this M.

233
00:15:59,800 --> 00:16:06,290
Distance plus, let's say the slope point, I will cover letters lowpoint, I will cover X around,

234
00:16:06,710 --> 00:16:08,840
OK, X complete round of the loop.

235
00:16:09,170 --> 00:16:11,600
So each round is of length L.

236
00:16:12,720 --> 00:16:16,890
So so this low point is covering the x rounds.

237
00:16:18,220 --> 00:16:20,620
Before intersection with the fast pointer.

238
00:16:20,720 --> 00:16:27,250
OK, so it's complete round and each round is of Lendell and then this distance key.

239
00:16:28,790 --> 00:16:31,770
OK, and what is the distance?

240
00:16:31,790 --> 00:16:35,270
So what is the distance travelled by the fast pointer?

241
00:16:36,110 --> 00:16:43,100
So distance traveled by a fast point that is first of all this distance M, so this distance M, let's

242
00:16:43,100 --> 00:16:47,730
say the number of rounds, the first point to go it ottavi.

243
00:16:47,810 --> 00:16:54,950
OK, so while each round is of length L and obviously this distance K OK.

244
00:16:55,970 --> 00:17:01,880
So what are X and why are you so X and Y are basically the rounds?

245
00:17:02,950 --> 00:17:06,160
Of the loop of the cycle before they intersect.

246
00:17:06,369 --> 00:17:06,730
OK.

247
00:17:07,770 --> 00:17:10,589
So so this is the clean bigram.

248
00:17:12,240 --> 00:17:19,770
OK, so this distance from the heart of the link to the starting point, this distances them.

249
00:17:20,700 --> 00:17:21,569
This is key.

250
00:17:21,750 --> 00:17:23,670
This distance is basically key.

251
00:17:23,700 --> 00:17:29,180
Advanced law enforcement intersect and the whole distance, the size of the loop is, well, OK.

252
00:17:29,490 --> 00:17:31,320
So I hope you know the equation.

253
00:17:31,410 --> 00:17:34,620
You know, both these equations will these equations are clear to you?

254
00:17:35,100 --> 00:17:41,670
OK, now one thing that we know, Fassbinder is moving with two x speed, OK?

255
00:17:41,940 --> 00:17:48,120
So if the speed of slow, pointillist X, then the speed of fast point is to X, that means the distance

256
00:17:48,120 --> 00:17:52,260
traveled by a fast pointer is twice the distance travelled by this little pointer.

257
00:17:53,140 --> 00:18:02,890
OK, so in mathematical terms, so distance travelled by a fast pointer is twice the distance traveled

258
00:18:02,890 --> 00:18:04,270
by the slow pointer.

259
00:18:04,840 --> 00:18:07,430
OK, so let's put it all here.

260
00:18:07,750 --> 00:18:12,400
So this is M plus right into L Klasky.

261
00:18:12,830 --> 00:18:15,670
OK, so twice and distance David Westlaw point.

262
00:18:15,670 --> 00:18:19,450
That is M plus X in into L plus K.

263
00:18:20,310 --> 00:18:22,560
OK, so what will happen.

264
00:18:22,570 --> 00:18:31,490
And plus Y into helpless K and multiply to inside so to M plus two excel plus 2k.

265
00:18:32,260 --> 00:18:32,740
OK.

266
00:18:34,640 --> 00:18:44,000
Now, what will happen, so take em decide, take the side and take to excel, decide, OK, so what

267
00:18:44,000 --> 00:18:44,530
will happen?

268
00:18:44,540 --> 00:18:46,640
This will become V minus two.

269
00:18:49,140 --> 00:18:51,330
And 2L is basically.

270
00:18:52,380 --> 00:18:56,100
McCleskey OK, so let me reiterate it.

271
00:18:58,950 --> 00:18:59,910
So basically.

272
00:19:02,270 --> 00:19:03,200
McCleskey.

273
00:19:04,740 --> 00:19:08,580
Is why minus two weeks and total.

274
00:19:09,120 --> 00:19:12,160
OK, and this is our simple diagram.

275
00:19:12,660 --> 00:19:15,470
So this is M and this is K.

276
00:19:18,180 --> 00:19:19,110
OK, so this is.

277
00:19:20,840 --> 00:19:26,920
Now, see, one thing here, emplace gay is an integer, multiple of L.

278
00:19:27,830 --> 00:19:28,490
What is L.

279
00:19:28,490 --> 00:19:30,410
L is basically the size of the loop.

280
00:19:33,170 --> 00:19:38,420
OK, so McCluskey is in danger, multiple of.

281
00:19:41,550 --> 00:19:43,520
Integer, multiple of L.

282
00:19:44,100 --> 00:19:48,450
OK, now can we put one here it is integer multiple.

283
00:19:48,480 --> 00:19:51,510
OK, so why am minus two weeks will be integer.

284
00:19:51,710 --> 00:19:53,040
OK, so it can be anything.

285
00:19:53,250 --> 00:19:54,740
Now suppose it is one.

286
00:19:55,770 --> 00:19:56,880
Suppose it is one.

287
00:19:57,060 --> 00:20:03,150
So basically what I'm writing here K is basically an OK, so suppose this value is one.

288
00:20:03,180 --> 00:20:06,540
This value can be to, this can be three, this value can be anything.

289
00:20:06,750 --> 00:20:09,900
But for the sake of understanding let's suppose this value is one.

290
00:20:10,410 --> 00:20:12,830
OK, so emplace is basically L.

291
00:20:13,170 --> 00:20:22,830
OK, so if this, so this distance is key, that means this distance is M ok because the total distance

292
00:20:22,830 --> 00:20:23,290
is L.

293
00:20:23,340 --> 00:20:25,140
OK, so the total size the loop is.

294
00:20:25,200 --> 00:20:34,080
And so if this much distance is key, if this much distance is K then obviously this will be M.

295
00:20:35,660 --> 00:20:37,200
OK, this is them.

296
00:20:37,820 --> 00:20:42,410
Now see here, so slow and fast pointer, slow and fast.

297
00:20:42,860 --> 00:20:44,480
Both are present at key.

298
00:20:44,840 --> 00:20:47,240
So I am drawing this diagram once again.

299
00:20:49,150 --> 00:20:53,990
This is both slow and fast pointer are presented.

300
00:20:54,270 --> 00:20:57,460
OK, so this distance is key.

301
00:21:00,620 --> 00:21:05,120
This distance is M and similarly, this distance is M.

302
00:21:05,570 --> 00:21:08,670
OK, so both slow and fast pointer are present here.

303
00:21:09,050 --> 00:21:12,080
Now what we did, we moved this slow pointer.

304
00:21:14,340 --> 00:21:17,430
To the head of the linked list, so this is Logan.

305
00:21:18,580 --> 00:21:22,540
Now, what we are doing, we are moving slow and fast at the same speed.

306
00:21:22,870 --> 00:21:25,970
OK, slow and fast are moving at the same speed.

307
00:21:26,200 --> 00:21:33,790
Now, what will happen when slow will cover em distance slow will reach here, slow will reach here

308
00:21:33,790 --> 00:21:35,620
after conveying the distance.

309
00:21:36,880 --> 00:21:41,020
And at the same time, fast will also cover the distance.

310
00:21:41,020 --> 00:21:45,550
M fast will cover the distance and it will also reach here.

311
00:21:46,060 --> 00:21:47,770
And that's how the code will work.

312
00:21:47,840 --> 00:21:49,960
OK, so I hope you understood the code.

313
00:21:50,480 --> 00:21:52,210
OK, so that's how this is working.

314
00:21:52,880 --> 00:21:54,970
If you have any doubt, feel free to ask.

315
00:21:55,000 --> 00:21:55,450
Thank you.

