Linked List Cycle
Given the head of a linked list, return true if it contains a cycle. Doing this with a Set of visited nodes works but uses O(n) space — the O(1)-space answer is Floyd's tortoise and hare: a slow pointer and a fast pointer (2 steps at a time) will always meet if there's a cycle, and the fast pointer will hit null if there isn't.
hasCycle(list(3, 2, 0, -4)); // false
// a list whose tail points back into itself → true