Full threadzeroonetwothree·This problem is called “online cycle detection” in the literature. You can search for various better algorithms that have been developed.View on HN