Distribution Center Package Allocation
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok reported this one in August 2026, and the trap is in the closure rule, not the allocation loop. Distribution Center Package Allocation looks like a plain simulation: a pointer walks the centers, burns capacity, wraps around, and you count per-center totals. Then a center closes mid-capacity and a naive pointer either double-counts or stalls on a dead center. If your OA invite is a day or two out, this is worth ten minutes of thought now. StealthCoder sits invisibly on your screen as a safety net if you blank during the live OA, but the logic below is small enough to hold in your head.
The problem
You manage a network of distribution centers indexed from 0 to n - 1. Center i can process centerCapacities[i] packages before it needs a reset. Process the entries of dailyLog in order. Every entry is one of: "PACKAGE": a package arrives for processing. "CLOSURE j": center j closes and remains unavailable for the rest of the process. Packages are assigned to centers in increasing index order, beginning at center 0. A center handles consecutive packages until its remaining capacity reaches 0, then allocation advances to the next available center. Closed centers are always bypassed. When allocation passes the end of the center array, one complete rotation has finished. Restore every operational center to its original capacity, continue from index 0, and keep bypassing closed centers. If a center closes while it still has unused capacity, the next package advances to the next available center. Return the index of the center that processed the most packages. If several centers processed the same maximum number, return the highest index among them. Function mostPackagesProcessed(centerCapacities: int[], dailyLog: String[]) → int Examples Example 1 centerCapacities = [2,1,3] dailyLog = ["PACKAGE","PACKAGE","PACKAGE","PACKAGE","CLOSURE 2","PACKAGE","PACKAGE","PACKAGE"] return = 0 Before the closure, centers 0, 1, and 2 process 2, 1, and 1 packages. Center 2 then closes. The next rotation assigns two packages to center 0 and one to center 1, so the totals are [4, 2, 1] and center 0 wins. Example 2 centerCapacities = [1,1,1] dailyLog = ["PACKAGE","PACKAGE","PACKAGE"] return = 2 Each center processes exactly one package. The totals are tied, so the highest center index, 2, is returned. Example 3 centerCapacities = [3,2,1] dailyLog = ["PACKAGE","CLOSURE 0","PACKAGE","PACKAGE","PACKAGE","PACKAGE"] return = 1 Center 0 processes one package and then closes with capacity remaining. Center 1 processes the next two packages, center 2 processes one, and the final package starts a new rotation at center 1. The totals are [1, 3, 1]. Constraints 1 <= centerCapacities.length 1 <= centerCapacities[i] <= 5 Every entry of dailyLog is either "PACKAGE" or "CLOSURE j" for a valid center index j. At least one center remains operational throughout the process.
Reported by candidates. Source: FastPrep
Pattern and pitfall
It's a direct simulation with three pieces of state: the current center index, the remaining capacity of that center, and a closed[] array. On PACKAGE, skip forward past closed centers, wrapping to 0 and resetting capacity when you pass the end. Then credit the current center, decrement its remaining capacity, and when it hits 0 advance the pointer. On CLOSURE j, mark closed[j]. If j is the current center, the next package must move on, so set remaining to 0 or advance lazily. The pitfall is a stale capacity: when you wrap, reload capacity for the new center, not the old one. Also remember ties go to the highest index, so scan counts with >=. Capacities are at most 5, so nothing needs optimizing. If the live OA freezes you on the wrap logic, StealthCoder is the hedge. Otherwise, just trace Example 3 by hand.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Distribution Center Package Allocation cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Distribution Center Package Allocation FAQ
What's the trick in the TikTok Distribution Center Package Allocation problem?+
It's a pure simulation. Track a pointer, remaining capacity, and a closed array. The trick is handling a closure on the center you're currently filling. Its leftover capacity must be discarded so the next package moves to the next open center.
How hard is this one really?+
Easy to medium. No fancy data structure is needed. The difficulty is off-by-one handling around wraparound and closures. If you trace the three examples by hand before coding, you'll catch nearly every bug.
Do I need to simulate rotations explicitly?+
Yes, but cheaply. When your pointer passes the last index, wrap to 0 and reload capacity for each center as you reach it. Closed centers are skipped, and the constraint guarantees at least one stays open, so the skip loop always ends.
How do I break ties correctly?+
After processing the log, scan the counts array and update your best index whenever count[i] >= best count. That makes the highest index win on ties, which is what Example 2 checks with its answer of 2.
How should I prepare for this in 48 hours?+
Write the simulation once from scratch, then test three cases: closure of the current center, closure of a later center before you reach it, and a full wrap with ties. Parsing 'CLOSURE j' by splitting on the space is the only string handling needed.