Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 With Doubly Linked Lists

HardSQL & Data Manipulation00:00
Practice interviewer
In session
5 left
00:00

Your question is Coding With Doubly Linked Lists. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

Veritas Technologies keeps a small in-memory doubly linked list inside its backup-catalog service to track the most recently touched backup jobs, so the most recent one can be found and removed quickly without rescanning the whole job list. A teammate wrote the class below to add jobs, delete a job by id, and read job ids in from the console, but it's already causing incorrect "recently touched" lists in staging.

class Node:
    def __init__(self, job_id):
        self.job_id = job_id
        self.prev = None
        self.next = None


class JobList:
    def __init__(self):
        self.head = None
        self.tail = None

    def add_front(self, job_id):
        node = Node(job_id)
        node.next = self.head
        self.head = node
        self.tail = node

    def delete(self, job_id):
        current = self.head
        while current.job_id != job_id:
            current = current.next

        if current.prev:
            current.prev.next = current.next
        if current.next:
            current.next.prev = current.prev

    def to_list(self):
        result = []
        node = self.head
        while node != self.tail:
            result.append(node.job_id)
            node = node.next
        return result


def load_jobs():
    jobs = JobList()
    raw = input("Enter job ids separated by spaces: ")
    for job_id in raw.split():
        jobs.add_front(job_id)
    return jobs

Walk through what happens when a few job ids are added and then one is deleted, and explain in writing everywhere this implementation loses or corrupts data.