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
Array, Linked List, Set Algorithms
00:00
5 left

Array, Linked List, Set Algorithms

HardPython

Problem

Tell me about how you would solve an algorithmic problem involving arrays, linked lists, and sets.

Implement analyze_and_reorder to traverse an index-based singly linked list, detect cycles, remove values in a forbidden set, and stably reorder the remaining values according to the priority order in an array. Values absent from the priority array must follow all prioritized values in their original traversal order.

The function returns [values, has_cycle], where values is the reordered list and has_cycle indicates whether traversal encountered a previously visited node.

Constraints

  • 0 <= len(order) <= 5,000
  • 0 <= len(nodes) <= 5,000
  • Each node has an integer value and a next index from -1 through len(nodes) - 1
  • The linked-list representation is valid when head is -1 or a valid node index
  • Values in order are unique
  • Values and node indices fit within standard Python integers
  • The forbidden collection supports expected O(1) membership checks

Function Signature

def analyze_and_reorder(order, nodes, head, forbidden):
Interviewer

Your question is Array, Linked List, Set Algorithms. 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.