The naive approach: use a hash set to track visited nodes. If you see a node twice, there's a cycle. But that uses space. For space, use the tortoise and hare algorithm. Have two pointers: slow moves one step, fast moves two steps. If there's no cycle, fast will reach the end. If there's a cycle, fast will eventually catch up to slow (they'll meet inside the cycle).
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/linked-lists/linked-list-cycle-hint
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████