Software Developer Mock Interview

Master 30 Software Developer interview questions covering algorithms, system design, and coding challenges.

Question 4 of 30

How do you find the starting node of a cycle if a link contains a cycle?

  • How to Answer 1

  • How to Answer 2

  • Example Answer

  • Community Answers

Tom Dushaj
Tom Dushaj

Tom Dushaj is a business and technology executive and the author of 'Resumes That Work.' Tom has vast experience providing solutions to Fortune 500 companies in the areas of Information Technology Consulting, ERP Software, Personnel Management, and Intern

I use Floyd's Cycle-Finding Algorithm to find the starting node of a cycle. I believe it to be the fastest method I have used. I make sure that every node is checked to see if the next one in the sequence is pointing to a temporary node or not. Here's an example of what I mean.

I can use traverse linked list pointers
Traverse linked lists using two pointers
I can move one pointer (slow_p) to one and another pointer (fast_p) by two.
If these pointers meet at the same mode, then there is a complete loop. On the other hand, if pointers do not meet, the linked list doesn't have a complete loop.

Unlock All 30 Software Developer Questions

Unlock expert responses to technical and behavioral questions interviewers ask developers.

Get Started