~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Cycle detection
Visited / on-stack sets; symlinks, CNAMEs, instruction loops.
Notes
Recognise it when: following pointers or links (CNAMEs, symlinks, instruction jumps, next pointers) that might loop.
- Chain walk: keep a
seenset for the current walk, and it's a cycle if you revisit. - Directed graph: DFS with three colours (white/grey/black). A grey node reached again means a cycle. Or run Kahn's and see whether nodes are left over.
- Linked list, O(1) space: Floyd's tortoise and hare.
- Many shared chains: memoize results so each node is resolved once (O(n) total).
Gotchas: "a -> a" self-loops, and chains into a cycle that doesn't include the start.
4 problems
Interview roadmap
Graphs Grids and networks: BFS, DFS, cycles, ordering.
Cycle detection guide
- Basics: does a directed graph have a cycle? basics py · c++ · java easy
- Spreadsheet: show the circular reference easy
- Find Eventual Safe States py · c++ · java medium
- Bootloader loop: detect and repair 3 levels Anthropic hard