From linkjobai, 1 Week ago, written in Plain Text.
Embed
  1. Linked List Cycle (LeetCode 141): Interview Notes
  2.  
  3. Problem
  4. Return true if a linked list has a cycle.
  5.  
  6. Approach
  7. Floyd: slow moves one, fast moves two. If they meet there is a cycle. Hashing visited nodes also works.
  8.  
  9. Complexity
  10. Time O(n), space O(1) for Floyd.
  11.  
  12. Practice tip
  13. Ask follow-ups (cycle entrance, length) with an AI interview copilot: https://www.linkjob.ai/interview-copilot/.
  14.  
  15. *Disclosure: I work on Linkjob AI.*
  16.