Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Loop Detection in Linked List
00:00
5 left

Loop Detection in Linked List

MediumPython

Problem

Detect a loop in a linked list.

Implement detect_loop(values, pos), where values is a list of node values and pos identifies the index reached by the final node. Use pos = -1 when the final node points to None. Return True if the resulting linked list contains a loop, otherwise return False.

Constraints

  • 0 <= len(values) <= 500
  • pos is -1 or a valid index in values
  • Values are integers

Function Signature

def detect_loop(values, pos):
Interviewer

Your question is Loop Detection in Linked List. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.