Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Coding: Linked List Loop Detection
00:00
5 left

Coding: Linked List Loop Detection

EasyPython

Problem

A Check Point security event pipeline stores events in a singly linked list. Implement the list construction and determine whether the list contains a loop, such as one caused by an incorrect event-linking operation.

The function receives a list of event identifiers and a loop position. It must build the linked list, connect the final node to the node at that position when applicable, and detect the loop using constant auxiliary space.

Formal Specification

Implement has_loop(values, loop_index). values is a list of integers used to create one node per value. loop_index is the zero-based index of the node that the final node should reference, or -1 when the list should terminate at None. Return True if the constructed list contains a loop, otherwise return False.

Use a singly linked-list node with value and next fields. Do not traverse indefinitely, and do not use a set of visited nodes in the primary solution.

Constraints

  • 0 <= len(values) <= 10^5
  • -10^9 <= values[i] <= 10^9
  • loop_index is -1 or a valid index in values
  • The input describes at most one loop

Function Signature

def has_loop(values, loop_index):
Interviewer

Your question is Coding: Linked List Loop Detection. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.