Parcel Event Tracking
Learn this problemProblem statement
Process a finite ordered sequence of operations for a simplified parcel-tracking system. Maintain parcels by string parcelId. Within each parcel, maintain a running signed 64-bit count for each string eventType.
Each row in operations is one of:
["RECORD", parcelId, eventType, count]: create the event-type counter if absent, add the positive decimal integercount, and return the new running total.["GET", parcelId, eventType]: return the current total, ornullif either the parcel or event type is absent.["REMOVE", parcelId, eventType]: remove that event-type counter and returntrueif it existed; otherwise returnfalse. After a successful removal, delete the parcel itself when it has no remaining event types.
Return a canonical JSON array string containing one result per operation in order. Integer totals are JSON numbers, missing queries are null, and removal results are JSON booleans. The returned string contains no spaces.
Only Level 1 is in scope. Parcel ranking, courier assignment, courier-specific events, undo, and courier sign-out are not part of this contract because the source images do not provide their rules.
Function
processParcelEvents(operations: String[][]) → StringExamples
Example 1
operations = [["RECORD","A","B","5"],["RECORD","A","B","6"],["GET","A","B"],["GET","A","C"],["REMOVE","A","B"],["REMOVE","A","B"]]return = "[5,11,11,null,true,false]"The first two records create then increment counter (A, B) to 11. Querying that counter returns 11, while event type C is absent. The first removal succeeds and deletes the now-empty parcel; repeating it returns false.
Example 2
operations = [["RECORD","P1","loaded","3"],["RECORD","P1","scanned","2"],["REMOVE","P1","loaded"],["GET","P1","scanned"],["GET","P1","loaded"]]return = "[3,2,true,2,null]"Removing loaded does not delete parcel P1 because its scanned counter remains. The removed event type is subsequently absent.
Example 3
operations = [["GET","missing","x"],["RECORD","missing","x","7"],["REMOVE","missing","x"],["RECORD","missing","x","4"],["GET","missing","x"]]return = "[null,7,true,4,4]"The first query sees no parcel. A successful removal deletes the only event type and therefore the parcel; recording the same identifiers afterward creates a fresh counter starting at 4.
Constraints
1 <= operations.length <= 2 * 10^5.- Every operation has exactly the name and number of fields described above.
1 <= parcelId.length, eventType.length <= 100.- Identifiers contain printable ASCII characters.
- Every
RECORDcount is a decimal integer from1through10^9. - Every running event count fits in a signed 64-bit integer.
More Airbnb problems
- Worker Management, Part 3: Promotions and SalaryOA · Seen Jul 2026
- Worker Management, Part 2: Top WorkersOA · Seen Jul 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Worker Management with Full-Shift Double PayOA · Seen Jul 2026
- Worker Management, Part 1: Office RegistrationOA · Seen Jul 2026
- Most Frequent Reduced DigitOA · Seen Jul 2026
- Rectangle Fit QueriesOA · Seen Jul 2026
- Robot Final DirectionOA · Seen Jul 2026