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
Recursive Linked List Insert
00:00
5 left

Recursive Linked List Insert

MediumPython

Problem

PTC's Windchill configuration structures may expose only a reference to a node within a singly linked sequence. Implement recursive insertion without receiving or using a separate head pointer.

You are given a non-empty Node reference, an integer value, and a zero-based index relative to that node. Insert the new value at that position and return the same starting node reference. Index 0 means insert before the referenced node.

Because the predecessor is unavailable, inserting before the referenced node must preserve the referenced object's identity. Use the copy-and-shift technique: replace its value with the new value, then create a node containing the old value immediately after it.

Formal Specification

Assume each node has integer field value and nullable next field. The function signature is insert_recursive_no_head(node, value, index). The input list is represented by the node reference and the output is the linked sequence reachable from that same reference. The index is guaranteed to be valid, from 0 through the current sequence length.

Constraints

  • The sequence contains 1 to 10^4 nodes.
  • -10^9 <= value <= 10^9.
  • 0 <= index <= n, where n is the current sequence length.
  • The supplied node is non-null and represents the first node of the accessible sequence.
  • The index is guaranteed to be valid.
  • The primary solution must use recursion and no separate head pointer.

Function Signature

def insert_recursive_no_head(node, value, index):
Interviewer

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