Viasat interview question

Using only two pointers how can you tell if a linked-list cycles?

Interview Answers

Anonymous

30 Mar 2013

Have both pointers iterate through the list except have one iterate at a faster rate like one traverses by 2 while the other traverses by 1. That way if the faster pointer ever catches up with the slower pointer you know that there is a cycle in the list.

4

Anonymous

12 Oct 2017

Tortoise and Hare

Anonymous

13 May 2016

Keep one pointer at the head. If the tail pointer is equal to head, there's a cycle