Approach hintTry it first, then revealHide
The digit-square sequence either reaches 1 or repeats forever. Detect repetition with a hash set of values seen, or run slow and fast pointers over the sequence as in cycle detection.
The digit-square sequence either reaches 1 or repeats forever. Detect repetition with a hash set of values seen, or run slow and fast pointers over the sequence as in cycle detection.