Linked List Cycle (LeetCode 141) | Full solution with demo | Floyd Warshall | Study Algorithms

  Рет қаралды 12,347

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 73
@sheldoncooper7990
@sheldoncooper7990 11 ай бұрын
You are just greek god of teaching complex stuff in the simplest way possible!! God bless for your efforts.
@nikoo28
@nikoo28 11 ай бұрын
haha...will try my best to keep bringing such content
@JammUtkarsh
@JammUtkarsh Жыл бұрын
I must say you speak very politely and your explanation is LIT 🔥 🔥 🔥 🔥. I personally find your videos better NeetCode. Hope your channel grows!!!💜
@nikoo28
@nikoo28 11 ай бұрын
As long as you understand things, it is all that matters. 🙂
@debottamyoutube
@debottamyoutube 7 ай бұрын
What an explaination. Calm, cool, smiling, no use of complex words, it was like listening to a story. ❤ Subscribed!!!
@pranavm9301
@pranavm9301 8 ай бұрын
Very good explanation. in while condition, slow != null is not required because slow pointer is always behind fast and if there is a null, it's detected by fast pointer and we break out of loop
@GrowWithHare
@GrowWithHare 3 ай бұрын
Wow, I can't imagine you explained this problem so well. Thanks a lot bhaiya❤😊
@johncho9160
@johncho9160 8 ай бұрын
can you pls explain what the purpose of fastPtr.next != null condition in the while loop? i understand that if slowPtr or fastPtr is null then it is not a cycle but why the third condition?
@nikoo28
@nikoo28 7 ай бұрын
we want to make sure that we don't hit null pointer. It is not necessary that the linked list has a cycle for sure
@preetijavali6595
@preetijavali6595 7 ай бұрын
Hi Thanks fo the video. Can you explain why while loop has 3 conditions? if fast pointer reaches null, its already proven that it doesnt have loo. also fast pointer will always reach null first, so why check for slow pointer is null or not? and why check fast pointer.next is null?
@nikoo28
@nikoo28 7 ай бұрын
you are right...we can get rid of slowPtr check in the while loop.
@preetijavali6595
@preetijavali6595 7 ай бұрын
@@nikoo28 Thank you.
@mahatrt
@mahatrt Ай бұрын
Hatsofff sirr🙌🫡🫡
@jayaveeran1
@jayaveeran1 3 ай бұрын
Hi Nikhil, thanks for the amazing video, just one query do we really need the condition slowPtr!=null on the while loop ?
@priyanshgarg1292
@priyanshgarg1292 Жыл бұрын
WHY NOT WE ARE moving hare with 3x or 4x or 5x etc... speed then also it will come in loop why only 2x speed?
@nikoo28
@nikoo28 Жыл бұрын
While you could potentially use a higher speed like 3x, 4x, or 5x, using a speed of 2x ensures that the hare and tortoise pointers will eventually meet if there is a cycle. Using a higher speed than 2x might not guarantee this outcome. Let's explore the reasoning behind using a 2x speed for the fast pointer: - Balanced Progress: Moving the fast pointer at 2x the speed of the slow pointer creates a balanced progression. This ensures that the fast pointer catches up to the slow pointer at a steady rate. - Guaranteed Intersection: In a linked list with a cycle, the fast pointer will eventually enter the cycle. Since the cycle has a finite length, the fast pointer will "lap" the slow pointer (that's moving at a 1x speed) before they meet again. - Avoiding Overlooking Cycles: If you were to use a higher speed for the fast pointer, like 3x or 4x, you might inadvertently overshoot or skip over some cycles. This is because the fast pointer might move through multiple complete cycles while the slow pointer is still traversing through a single cycle. - Minimal Tracking: Using a 2x speed minimizes the number of steps required to find a cycle. While increasing the speed might lead to faster movement, it doesn't guarantee a more efficient cycle detection process.
@IshaZaka
@IshaZaka 23 күн бұрын
plz make more videos, its so helpful
@TechTribers
@TechTribers 3 ай бұрын
very good explanation & easy to understand . Jus wanted to ask which application you use for writing in ipad like (goodnote ,notability)
@nikoo28
@nikoo28 3 ай бұрын
GootNotes 6
@infinite639
@infinite639 2 жыл бұрын
I can run the code on Leetcode but But i want to run it on my local IDE as a normal input output program You have only written test cases
@nikoo28
@nikoo28 2 жыл бұрын
You can just copy the test case inside the main method and it will work
@sharabugnanesh3098
@sharabugnanesh3098 Жыл бұрын
I can't find the solution for this thing "Where to find the cycle first"😢
@nikoo28
@nikoo28 11 ай бұрын
this: kzbin.info/www/bejne/b2a9l6iliKaIhqs
@alisheheryar1770
@alisheheryar1770 6 ай бұрын
You hoped you simplified the solution. And yes you are Sire! you indeed simplified it. I hope i could give you a cookie.
@hamdasalam4373
@hamdasalam4373 3 ай бұрын
What an awesome explanation.Sir could you please come up with the continuation of the video on how to find the node at which the cycle occurs?, will be of great help
@kayathrivenkatesan7712
@kayathrivenkatesan7712 5 ай бұрын
thank u so much .i have been searching only for ur solution for evry prblm and go to other videos only if ur video is not present.ur videos and visuals bring more interest for me to solve problems
@shraddhajain8935
@shraddhajain8935 2 жыл бұрын
Hey! can you explain the while condition a bit more? For me it is failing for a test case like '[-21,10,17,8,4,26,5,35,33,-7,-16,27,-12,6,29,-12,5,9,20,14,14,2,13,-24,21,23,-21,5] -1' when it comes to a point where 'fast.next.next' is None. It is working when we are adding a null check for fast.next.next as well
@matthewzarate8851
@matthewzarate8851 4 ай бұрын
Your entire linked list playlist is amazing Nikhil!
@Dadu-g4r
@Dadu-g4r Жыл бұрын
Great explanation 🔥
@abuyousuf7281
@abuyousuf7281 9 ай бұрын
Sorry bro! Your solution exceeded the time limit of leetcode constraints. This approach is not accepted in Leetcode.
@nikoo28
@nikoo28 9 ай бұрын
That can’t be possible, did you check the code in the github link available in the description? It passes on LeetCode
@abuyousuf7281
@abuyousuf7281 9 ай бұрын
@@nikoo28 sorry brother about my last comment. Yes this approach is good enough but I tried your same concept but that showed time limit exceeded. I want to let you know that I used Java. But after that I had seen another video which is same approach but differently. Like: ListNode slow = head; ListNode fast = head.next;a while(){ .... slow = slow.next; fast = fast.next.next; } Return true; And Buddy that passed the time limit constraint.
@abuyousuf7281
@abuyousuf7281 9 ай бұрын
@@nikoo28 Don't get me wrong sir, You’ve done an amazing job. Just wanted to let you know I've failed to pass my time limit.
@akashchakrabortty2431
@akashchakrabortty2431 Жыл бұрын
Thanks Nikhil, for explaining the approach so nicely
@vaibhavkgote
@vaibhavkgote Жыл бұрын
what application do you use to write in tab?
@nikoo28
@nikoo28 Жыл бұрын
That would be Goodnotes 6.
@vaibhavkgote
@vaibhavkgote Жыл бұрын
@@nikoo28 Thank you !
@Thirushal007
@Thirushal007 7 ай бұрын
such a simple explaination
@divyaawasthi8286
@divyaawasthi8286 11 ай бұрын
Nikhil Bhai, Thankyou so much i got clarity on LL through your videos only...Very clear explanation you are doing great job Brother Proud of you.
@nikoo28
@nikoo28 11 ай бұрын
thanks so much
@chakravarthybatna1589
@chakravarthybatna1589 Жыл бұрын
your channel is underated, your videos are amazing bro , awesome explanation please keep posting new video's in english
@nikoo28
@nikoo28 Жыл бұрын
I will try my best
@shivangchauhan820
@shivangchauhan820 Жыл бұрын
It would be good If you have made this video in hindi as there are not much viewers who don't understand hindi.
@nikoo28
@nikoo28 Жыл бұрын
i will try to add subtitles in other languages
@arupbasak919
@arupbasak919 Жыл бұрын
Really I love your way of explanation...Also it made me easy to understand..
@nikoo28
@nikoo28 Жыл бұрын
Happy to help
@rodba1393
@rodba1393 7 ай бұрын
thank you so much you are the best!!!!!
@mayankbadika3101
@mayankbadika3101 7 ай бұрын
Great explanation :)
@AadeshKulkarni
@AadeshKulkarni 7 ай бұрын
Beautiful baba!
@safar19899
@safar19899 Жыл бұрын
Great explanation! Thank you!
@ashokrajan9401
@ashokrajan9401 2 жыл бұрын
Very nice explanation Brother
@parthmodi2028
@parthmodi2028 7 ай бұрын
Ur vidoes are really helpful. Pls cover more problems
@nikoo28
@nikoo28 6 ай бұрын
a new video every week.
@JH-wy2pc
@JH-wy2pc 10 ай бұрын
Superb explanation
@kidoo1567
@kidoo1567 Жыл бұрын
Is this approach correct.. change the value of every node we are traversing as max integer. And check if we reach the node max integer again while traversing print true😅
@nikoo28
@nikoo28 11 ай бұрын
that works too, but then you are modifying the actual list. confirm with your interviewer if you are allowed to make changes.
@kidoo1567
@kidoo1567 10 ай бұрын
Yeah
@CodingSquirrel777
@CodingSquirrel777 Жыл бұрын
Thank you AGAIN!!
@hunorvadasz-perhat6001
@hunorvadasz-perhat6001 Жыл бұрын
Very nice and easy to understand explanation! Subscribed! 😄
@nikoo28
@nikoo28 Жыл бұрын
thank you for subscribing.. :)
@kalyanamvenumadhav2245
@kalyanamvenumadhav2245 Жыл бұрын
How to display value instead of true and false
@nikoo28
@nikoo28 Жыл бұрын
Once you identify the node you stop at, you can store it's value somewhere and then return it.
@TuringTested01
@TuringTested01 Жыл бұрын
youre an amazing tutor nikhil! Cheers
@nikoo28
@nikoo28 Жыл бұрын
thanks for the comment
@Sai-fn4lq
@Sai-fn4lq Жыл бұрын
Thanks a ton sir !! subbed🙂
@nikoo28
@nikoo28 11 ай бұрын
Thanks for the sub!
@SATYAMTIWARI-ps3wb
@SATYAMTIWARI-ps3wb Жыл бұрын
superb explanation boss
@nikoo28
@nikoo28 11 ай бұрын
Keep watching
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 24 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 39 МЛН
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 2,8 МЛН
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 95 М.
Top 7 Data Structures for Interviews Explained SIMPLY
13:02
Codebagel
Рет қаралды 194 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 238 М.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН