Distribution Center Package Allocation
Learn this problemProblem statement
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": centerjcloses 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[]) → intExamples
Example 1
centerCapacities = [2,1,3]dailyLog = ["PACKAGE","PACKAGE","PACKAGE","PACKAGE","CLOSURE 2","PACKAGE","PACKAGE","PACKAGE"]return = 0Before 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 = 2Each 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 = 1Center 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.length1 <= centerCapacities[i] <= 5- Every entry of
dailyLogis either"PACKAGE"or"CLOSURE j"for a valid center indexj. - At least one center remains operational throughout the process.
More Tiktok problems
- Count Access Code PairsOA · Seen Aug 2026
- Count Case-Insensitive TripletsOA · Seen Aug 2026
- Linear Warehouse Drone DeliveryOA · Seen Aug 2026
- Optimize TikTok Reels ViewingOA · Seen Aug 2026
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Shift Every K-th ConsonantOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026