Level: Senior-Level
Round: Online Assessment · Type: System Design · Difficulty: 6/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: System Design, Data Structures, Hashmaps, Time Management
Location: Mountain View, CA
Interview date: 2026-01-31
Design a worker management system as part of the online assessment.
The task was to design a worker management system with the following functionalities:
boolean addWorker(String workerId, String position, int compensation)
workerId already exists, do nothing and return false.true.workerId and position consist of only English letters and spaces.String registerWorker(String workerId, int timestamp)
timestamp.workerId is not in the system, return "invalid_request"."registered" if the entry or exit is recorded successfully.int get(String workerId)
-1 if workerId is not found in the system.Example Usage:
`java OfficeManager officeManager = new OfficeManager();
officeManager.addWorker("Ashley", "Middle Developer", 150); // true officeManager.addWorker("Ashley", "Junior Developer", 100); // false officeManager.registerWorker("Ashley", 10); // "registered" officeManager.registerWorker("Ashley", 25); // "registered" officeManager.get("Ashley"); // 15 (25 - 10) officeManager.registerWorker("Ashley", 40); // "registered" officeManager.registerWorker("Ashley", 67); // "registered" officeManager.registerWorker("Ashley", 100); // "registered" officeManager.get("Ashley"); // 42 ((25-10) + (67-40)) officeManager.get("Walter"); // -1 officeManager.registerWorker("Walter", 120); // "invalid_request" `
My Approach:
I would use HashMaps to store worker information and their entry/exit times. I would need to handle edge cases like invalid worker IDs and incomplete work sessions. The timestamps are strictly increasing, which simplifies time calculations.
`python from typing import Dict
class Employee: def init(self, role: str, salary: int): self.role = role self.salary = salary self.lastEntryTime = None # None means currently not in office self.totalTimeInOffice = 0 self.present = False # Track if employee is currently in office
class WorkerSystem: def init(self): self.employees: Dict[str, Employee] = {}
def addWorker(self, workerId: str, role: str, salary: int) -> bool:
if workerId in self.employees:
return False
self.employees[workerId] = Employee(role, salary)
return True
def registerWorker(self, workerId: str, timestamp: int) -> str:
emp = self.employees.get(workerId)
if emp is None:
return "invalid_request"
if not emp.present: # Employee is entering
emp.lastEntryTime = timestamp
emp.present = True
else: # Employee is leaving
emp.totalTimeInOffice += timestamp - emp.lastEntryTime
emp.present = False
emp.lastEntryTime = None # Reset entry time
return "registered"
def get(self, workerId: str) -> int:
emp = self.employees.get(workerId)
if emp is None:
return -1
return emp.totalTimeInOffice
`
Key Considerations: