Interview questions · Visa
Design rotating warehouse simulator with closures
This question evaluates algorithmic skills in designing efficient dynamic data structures and performing event-driven simulation with mutable state, specifically managing cyclic capacity resets and permanent closures in the Coding & Algorithms domain.
Given an integer array cap[0..n-1] for warehouses 0..n-1 and a sequence of events, simulate package processing. Events: (1) "PACKAGE": process one package by assigning it to the first warehouse at or after the current pointer (initially 0) that is not permanently closed and has remaining capacity in the current cycle; when a warehouse hits its capacity in the current cycle, it is considered full and skipped until the next cycle; advance the pointer to the next eligible warehouse after each package. (2) "CLOSURE x": permanently close warehouse x so it never processes packages again. Cycle reset: when warehouse n-1 becomes full and there is no eligible warehouse afterward in the current cycle, the next PACKAGE begins a new cycle where remaining capacities of all non-closed warehouses reset to cap[i]; closures persist. After processing all events, return the id of the warehouse that processed the most packages; break ties by returning the largest id. Design data structures and an algorithm with low per-event complexity and describe edge cases (e.g., if all warehouses are closed).
Community answers
Nothing here yet.
Join in on CSWork →