PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

Build an employee attendance and payroll tracker with shifts, time rankings, scheduled promotions, and double-pay windows. Preserve role and rate snapshots, apply promotions at the correct clock-in, merge overlapping bonus intervals, and compute salary from closed shifts.

  • hard
  • Anthropic
  • Coding & Algorithms
  • Software Engineer

Build a Progressive Employee Tracker

Company: Anthropic

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

# Build a Progressive Employee Tracker The source reports four tracker stages but not exact calls or failure values. The command driver and ordering rules below are deterministic practice assumptions. Implement: ```python def run_employee_tracker(operations: list[list[object]]) -> list[object]: ... ``` Every command contains a nonnegative timestamp. Command timestamps are nondecreasing, and equal-timestamp commands execute in list order. Return one result per command. ## Stage 1: Employees and Attendance - `["ADD", timestamp, employee_id, role, pay_rate] -> bool` creates an employee. Duplicate IDs return `False`. - `["CLOCK_IN", timestamp, employee_id] -> bool` opens a shift. It returns `False` for an unknown employee or one already clocked in. - `["CLOCK_OUT", timestamp, employee_id] -> bool` closes the open shift as `[clock_in, timestamp)`. It returns `False` for an unknown employee or one without an open shift. A zero-length shift is valid. `role` is a nonempty string and `pay_rate` is a nonnegative integer amount per minute. A closed shift stores the role and rate active at its start. Failed transitions change nothing. ## Stage 2: Statistics - `["TOTAL_TIME", timestamp, employee_id] -> int | None` returns completed shift minutes, or `None` for an unknown employee. Open shifts contribute zero until closed. - `["TOP_TIME", timestamp, n] -> list[list[object]]` returns `[[employee_id, completed_minutes], ...]` for up to `n` employees, sorted by completed minutes descending and employee ID ascending. Return `[]` when `n <= 0`. ## Stage 3: Promotions - `["PROMOTE", timestamp, employee_id, new_role, new_pay_rate, effective_at] -> bool` schedules one promotion. It requires an active employee and `effective_at > timestamp`. Each employee may have at most one pending promotion. A second request returns `False` until the pending promotion is applied. A pending promotion is applied immediately before the employee's first successful `CLOCK_IN` at a timestamp greater than or equal to `effective_at`. It never changes an already-open shift. A failed clock-in does not apply it. Once applied, another promotion may be scheduled. ## Stage 4: Double-Pay Windows - `["ADD_BONUS", timestamp, start, end] -> bool` adds a global half-open interval `[start, end)`, where `0 <= start < end`. Valid windows always return `True`, including redundant or overlapping windows. - `["SALARY", timestamp, employee_id, start, end] -> int | None` returns compensation from closed shifts intersected with `[start, end)`, or `None` for an unknown employee. Require `0 <= start <= end`. For each intersected minute, use the rate captured when that shift began. Minutes covered by at least one bonus window earn `2 * rate`; overlap never produces a multiplier above two. Bonus windows affect salary queries immediately and may cover shifts that closed before the window was added. Open shifts are excluded. An empty query range returns `0`. ## Errors and Performance - Unknown employees and invalid state transitions use the documented `False` or `None` result. - A malformed command, unknown command, decreasing timestamp, negative rate, empty role, invalid effective time, or invalid interval raises `ValueError` before mutation. - Preserve closed shifts and rate snapshots for range queries. Explain the complexity of attendance, ranking, promotion, interval-union, and salary operations. Test equal timestamps, promotion while a shift is open, a due promotion followed by an invalid clock-in, ranking ties, touching bonus windows, overlapping windows, zero-length shifts, and an open shift during a salary query.

Quick Answer: Build an employee attendance and payroll tracker with shifts, time rankings, scheduled promotions, and double-pay windows. Preserve role and rate snapshots, apply promotions at the correct clock-in, merge overlapping bonus intervals, and compute salary from closed shifts.

Process timestamped employee, attendance, ranking, promotion, bonus-window, and salary operations. Closed shifts retain the role and pay rate active when the shift began. Promotions apply only immediately before the first successful due clock-in, and overlapping bonus windows never raise the multiplier above two. Return one result for every operation.

Constraints

  • Command timestamps are nonnegative and nondecreasing; equal timestamps execute in input order.
  • Roles are nonempty strings and pay rates are nonnegative integer amounts per minute.
  • Only completed shifts contribute to time rankings and salary.
  • Bonus windows are half-open and their union receives double pay.
  • Malformed commands raise ValueError before their mutation.

Examples

Input: ([["ADD", 0, "a", "dev", 10], ["CLOCK_IN", 1, "a"], ["CLOCK_OUT", 6, "a"], ["TOTAL_TIME", 6, "a"], ["TOP_TIME", 6, 1]],)

Expected Output: [True, True, True, 5, [["a", 5]]]

Explanation: A completed shift contributes to total time and ranking.

Input: ([["ADD", 0, "a", "dev", 10], ["ADD", 1, "a", "qa", 9], ["CLOCK_OUT", 2, "a"], ["CLOCK_IN", 2, "missing"], ["TOTAL_TIME", 2, "missing"]],)

Expected Output: [True, False, False, False, None]

Explanation: Duplicate employees and invalid attendance transitions do not mutate state.

Hints

  1. Capture the current role and rate in each shift when CLOCK_IN succeeds.
  2. Apply a due promotion only after confirming that the employee can successfully clock in.
  3. For salary, clip and merge bonus intervals within each shift-query intersection.
Last updated: Jul 15, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Build a Progressive Banking Ledger - Anthropic (hard)
  • Build a Versioned In-Memory Database - Anthropic (hard)
  • Simulate Threshold Infection Efficiently - Anthropic (hard)
  • Build a Progressive Cloud Storage System - Anthropic (hard)