employer cover photo
employer logo
employer logo

Hughes Network Systems

Fait partie de EchoStar

Employeur impliqué

Question d’entretien chez Hughes Network Systems

How do you Catch Loops in Two Passes

Réponse à la question d'entretien

Utilisateur anonyme

5 janv. 2014

Simultaneously go through the list by ones (slow iterator) and by twos (fast iterator). If there is a loop the fast iterator will go around that loop twice as fast as the slow iterator. The fast iterator will lap the slow iterator within a single pass through the cycle. Detecting a loop is then just detecting that the slow iterator has been lapped by the fast iterator. Ref:http://ostermiller.org/find_loop_singly_linked_list.html