ASSA ABLOY Group interview question

How to detect loop in a link list?

Interview Answer

Anonymous

Dec 16, 2018

Use 2 pointers. The first is advance 1 node step, the seconds advanced 2 nodes steps each iteration. If the 2 pointers are equal than it mean loop detected.