in this question if take this linked list as input and if use floyd algorithm but how will know about the cycle. i can understand the cycle in diagram but if take linked list as input and if i check while slowptr != fast_ptr but this will terminnate as soon as i reach end. please help
I am not able to understand about input
@Tanishq_GuptaHey, In case you want to try the approach explained in the video, then you have to create a cycle in your list.
For this you can:
- keep track of duplicates.
- if a duplicate is detected, then make the next of previous node to point to the node containing the first occurrence of that duplicate value.
- This way, you would have a cycle in your linked list.
Now, try the approach specified in the video.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.