Join Nostr
2026-10-14 10:08:00 UTC
in reply to

codementor on Nostr: Both are O(n) time. The HashSet is simpler: the first node you see twice is the loop ...

Both are O(n) time.

The HashSet is simpler: the first node you see twice is the loop start. But it stores nodes, so it needs O(n) memory.

Fast and slow pointers need only O(1) memory. In an interview, give the HashSet idea first, then improve it.

#ll012 · LL-012-A3