FastPrepProgressive Parcel Tracking Operations
Problems/Progressive Parcel Tracking Operations

Progressive Parcel Tracking Operations

Klaviyo logoKlaviyo● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Klaviyo online assessment. The original report describes a parcel tracker built as a class, in levels that build on each other. It does not give one way to run a batch of operations or one type for all results. Here, you get an ordered list of operations. We keep the state changes the report describes.

Build a parcel tracker that changes state as operations arrive. Your function gets operations, a list of rows to run in order. Each row is one of these:

  • ["RECORD", parcelId, eventType, count]
  • ["GET", parcelId, eventType]
  • ["REMOVE", parcelId, eventType]
  • ["RANK", limit]
  • ["ACQUIRE", courierId, parcelId]
  • ["RELEASE", parcelId]
  • ["COURIER_RECORD", courierId, parcelId, eventType, count]
  • ["COURIER_REMOVE", courierId, parcelId, eventType]
  • ["UNDO", courierId, parcelId]
  • ["SIGN_OUT", courierId]

Each parcel keeps a total for each event type. RECORD adds the given count, which is always positive, to the parcel's total for that event type. It returns the new total. GET returns that total, or null if it does not exist. REMOVE deletes one whole event type from the parcel and returns whether it existed. When the parcel's last event type is deleted, its live record is deleted too.

Each live parcel also has a modification count. Every successful record or removal adds one to it. RANK returns up to limit live parcels. Sort them by modification count, highest first, and break ties by parcel ID in ascending order. Write each parcel as parcelId>(count), where count is its modification count, and join them with a comma and a space. If a parcel is deleted and later created again, its modification count starts over.

ACQUIRE assigns an existing parcel to a courier. It saves a snapshot of the parcel and returns acquired. Once the parcel is assigned, the same courier gets null from another acquire, and any other courier gets already_locked. A parcel that is not assigned and does not exist gives invalid_request. RELEASE ends the assignment and returns released. It returns null for a live parcel that is not assigned. It returns invalid_request when the parcel has no live data and no assignment.

While a parcel is assigned, ordinary writes are blocked. A blocked RECORD returns the current total, or null if there is none. A blocked REMOVE returns false. Operations from the courier that holds the parcel can still change it. Operations from a different courier get the same blocked results. The assignment stays in place even after all of the parcel's live event data is deleted. Such a parcel counts as assigned, not as missing, because the assignment is checked first.

UNDO works only for the courier that currently holds the parcel. It puts back the full snapshot taken at assignment time, including the modification count. Then it ends the assignment and returns true. In every other case it returns false. SIGN_OUT ends every assignment the courier holds, without rolling anything back, and returns how many it ended.

Return one string for each operation. Write integers in decimal and booleans in lowercase. A null result is written as "null". Status strings stay as they are. An empty ranking is the empty string.

Function

processParcelOperations(operations: String[][]) → String[]

Examples

Example 1

operations = [["RECORD","p1","scan","5"],["GET","p1","scan"],["RECORD","p1","scan","6"],["REMOVE","p1","scan"],["GET","p1","scan"]]return = ["5","5","11","true","null"]

The two RECORD rows add up to 11 for p1's scan events. REMOVE then deletes scan, which is p1's only event type, so p1's live record is deleted too. The last GET finds nothing and returns null.

Example 2

operations = [["RECORD","p1","scan","1"],["RECORD","p1","scan","1"],["RECORD","p2","scan","1"],["RANK","2"],["REMOVE","p1","scan"],["RECORD","p1","scan","4"],["RANK","2"]]return = ["1","2","1","p1>(2), p2>(1)","true","4","p1>(1), p2>(1)"]

At the first RANK, p1 and p2 have modification counts 2 and 1. REMOVE deletes p1, and the next record creates it again, so its count starts over. At the second RANK the counts tie, so parcel ID decides and p1 comes before p2.

Example 3

operations = [["RECORD","p","scan","3"],["ACQUIRE","c1","p"],["RECORD","p","scan","2"],["COURIER_RECORD","c2","p","scan","2"],["COURIER_RECORD","c1","p","scan","2"],["COURIER_REMOVE","c1","p","scan"],["ACQUIRE","c2","p"],["UNDO","c1","p"],["GET","p","scan"]]return = ["3","acquired","3","3","5","true","already_locked","true","3"]

Courier c1 acquires p after its first record. The plain RECORD and c2's COURIER_RECORD are both blocked, so each just returns the current total. c1's COURIER_RECORD goes through and raises the total. c1's COURIER_REMOVE then deletes all of p's live data. p is still assigned to c1, so c2's ACQUIRE gets already_locked. c1's UNDO restores the snapshot and ends the assignment, so the last GET returns the total from before the acquire.

Constraints

  • 1 <= operations.length <= 100000.
  • Each record count is a positive integer of at most 10^9. Every total fits in a signed 64-bit integer.
  • Each ranking limit is between 0 and 100000, inclusive.
  • Modification counts fit in a signed 32-bit integer.
  • Identifiers are nonempty and have at most 100 characters. They use only ASCII letters, digits, underscore, hyphen, period, or colon.
  • Every row has exactly the tag and the number of fields shown in the problem statement.

More Klaviyo interview questions

  • Banking Transfers, Account Merges, and Historical BalancesOA · Seen Jul 2025
  • In-Memory Database with Permanent and Expiring ValuesOA · Seen Jul 2025
  • File Storage with User Quotas, Merging, Backups, and RestoreOA · Seen Jun 2025
  • Key-Value Locks with Waiting QueuesOA · Seen Sep 2024
  • Render Sidebar Labels as HTMLONSITE INTERVIEW · Seen Jul 2025
  • Trace Logs at a Two-Second CadenceONSITE INTERVIEW · Seen Jul 2025
  • Validate Input Against Length BoundsONSITE INTERVIEW · Seen Jul 2025
  • Flatten JSON into Repeated Key-Value PairsONSITE INTERVIEW · Seen Oct 2023
  • Conditionally Insert or Update RecordsONSITE INTERVIEW · Seen Jul 2022

Similar questions at other companies

  • In-Memory File SystemAirbnb · OAAirbnb interview questions
  • Power Cell BankOptiver · OAOptiver interview questions
  • Four-Level Banking System with Scheduled PaymentsZipRecruiter · OAZipRecruiter interview questions
  • Task Management SystemCoinbase · OACoinbase interview questions
  • Task Management SystemAnthropic · OAAnthropic interview questions
  • Versioned Recipe SystemThe Trade Desk · OA
  • Recipe Management SystemRamp · OARamp interview questions
  • Document and Layer OperationsFigma · OAFigma interview questions
  • Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
  • Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions

Klaviyo interview experiences

  • Klaviyo SWE Intern Interview Questions: 15 Experiences
All Klaviyo interview questionsSee Klaviyo hiring insights
Saved
class Solution {
    public String[] processParcelOperations(String[][] operations) {
        // Write your code here.
    }
}
Checking account…