Back to Brain Tonic
AlgorithmsmediumBT-152
#152 Cycle Detection Gambit
You're given a function f: {0,...,n−1} → {0,...,n−1}. Starting from x₀, generate x₀, f(x₀), f(f(x₀)), ... This sequence must eventually repeat. Find the start of the cycle and its length using O(1) extra space.