Design a Package Tracking System with Courier Assignment, Event Recording, Undo, and Sign-Out
Implement a multi-level package tracking system supporting: recording parcel events under an assigned courier (RecordCourierEvent), querying total event counts per courier across all parcels (GetCourierEventCount), undoing the most recent courier assignment change for a parcel (UndoCourierChange), and signing out couriers with appropriate state transitions — signed-out couriers cannot be assigned or record events, their parcels become unassigned, and the unassignment does not create an undo-history entry.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late August, 2026
### `RecordCourierEvent` ```csharp int? RecordCourierEvent(string parcelId, string eventType, int count) ``` Records an event for a parcel under its currently assigned courier. - Updates the parcel event count exactly as `RecordEvent`. - Returns the updated parcel event count. Returns `null` if: - The parcel does not exist. - The parcel has no assigned courier. - The assigned courier has signed out. Events remain associated with the courier assigned when they were recorded. ### `GetCourierEventCount` ```csharp int? GetCourierEventCount(string courierId, string eventType) ``` Returns the total count of a given event type recorded by a courier across all parcels. Returns `null` if: - The courier does not exist. - The courier has never recorded that event type. ### Example ```csharp RecordEvent("parcel1", "created", 1); AddCourier("courier1"); AddCourier("courier2"); AssignCourier("parcel1", "courier1"); RecordCourierEvent("parcel1", "scan", 3); AssignCourier("parcel1", "courier2"); RecordCourierEvent("parcel1", "scan", 2); ``` Results: ```csharp GetEventCount("parcel1", "scan"); // 5 GetCourierEventCount("courier1", "scan"); // 3 GetCourierEventCount("courier2", "scan"); // 2 ``` --- ## Level 4 — Undo and Sign-Out ### `UndoCourierChange` ```csharp bool UndoCourierChange(string parcelId) ``` Reverts the most recent courier assignment change for a parcel. Example history: ```text no courier -> courier1 -> courier2 ``` Calling `UndoCourierChange("parcel1")` restores `courier1`. Calling it again restores the unassigned state. Returns `false` if: - The parcel does not exist. - No previous assignment state is available. Undoing an assignment does not alter previously recorded events. ### `SignOutCourier` ```csharp bool SignOutCourier(string courierId) ``` Signs a courier out. Returns `false` if: - The courier does not exist. - The courier has already signed out. Otherwise, signs the courier out and returns `true`. After sign-out: - The courier cannot be assigned to parcels. - Courier-specific events cannot be recorded under that courier. - Parcels assigned to that courier become unassigned. - This automatic unassignment does **not** create an undo-history entry. - The courier ID remains permanently registered. - `AddCourier` must return `false` for that ID. - The courier cannot be reactivated. ### Example ```csharp RecordEvent("parcel1", "created", 1); AddCourier("courier1"); AddCourier("courier2"); AssignCourier("parcel1", "courier1"); AssignCourier("parcel1", "courier2"); UndoCourierChange("parcel1"); // Restores courier1 SignOutCourier("courier1"); // Returns true ``` After sign-out, `parcel1` is unassigned. Calling `UndoCourierChange("parcel1")` returns `false` because the earlier undo already consumed the assignment history.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.