Welcome to the Python screen.
The question is on your right: Detect Cycle in Linked List. Read through the requirements first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
At Slack, a service may receive malformed linked-list structures from an in-memory cache. Write a function that determines whether a singly linked list contains a cycle.
A cycle exists if following next pointers eventually revisits a previously seen node instead of reaching None.
Implement a function that takes the head of a singly linked list and returns a boolean:
head, the first node of a singly linked list, or NoneTrue if the list contains a cycle, otherwise FalseEach node has:
val: integer valuenext: reference to the next node or Nonenext pointer to another node or Nonedef has_cycle(head):