Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Linked List Implementation
00:00
5 left

Linked List Implementation

MediumPython

Problem

The international advanced analytics data platform needs an in-memory sequence structure for workloads with frequent insertions and removals at both ends. Implement a mutable doubly linked list and process a sequence of commands while preserving correct head, tail, and length invariants.

Formal Specification

Write process_linked_list(operations), where operations is a list of command arrays. Return a list containing results only for commands that produce output:

  • ['append', value]: Add value to the end.
  • ['prepend', value]: Add value to the beginning.
  • ['insert', index, value]: Insert at index, returning true if valid and false otherwise.
  • ['get', index]: Return the value at index, or null if invalid.
  • ['delete', index]: Remove and return the value at index, or null if invalid.
  • ['pop_front'] and ['pop_back']: Remove and return an end value, or null when empty.
  • ['reverse']: Reverse the list in place.
  • ['length']: Return the current number of elements.

Values are integers. Indexing is zero-based. insert accepts indices from 0 through the current length.

Constraints

  • 1 <= len(operations) <= 10^5
  • -10^9 <= value <= 10^9
  • Each command has valid syntax and a recognized operation name
  • Indices are integers and may be outside the current valid range
  • The list must maintain correct head, tail, prev, next, and length invariants

Function Signature

def process_linked_list(operations):
Interviewer

Your question is Linked List Implementation. 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.