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).
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.