Busiest Distribution Center
Updated
Problem statement
Simulate one day of package routing across distribution centers 0, 1, ..., n - 1. In each round, center j can take up to centerCapacity[j] packages. Keep two pieces of state: a current center cur, which starts at 0, and room[j], which starts at centerCapacity[j] for every center.
Each entry of dailyLogs, taken from first to last, does one of two things:
"CLOSED j": centerjis out of service from this entry onward. Nothing else changes:curstays where it is, and no room is given back."PACKAGE": while centercuris out of service orroom[cur]is0, advancecur. Advancing fromn - 1setscurto0and resets everyroom[j]tocenterCapacity[j], which starts a new round. Then centercurtakes the package, androom[cur]drops by 1.
Let total[j] be the number of packages center j took over the whole log, including packages taken before it went out of service. Among the centers whose total equals the maximum total, return the largest center number.
Function
busiestCenter(centerCapacity: int[], dailyLogs: String[]) → intExamples
Example 1
centerCapacity = [2,4,1,5]dailyLogs = ["CLOSED 3","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE"]return = 1CLOSED 3comes before any package, so center3never takes one.- Round 1: center
0takes packages 1 and 2, center1takes packages 3 to 6, and center2takes package 7. The pointer then passes center2and the closed center3and wraps around, which starts round 2 with all capacities back. - Center
0takes packages 8 and 9. Final counts:[4, 4, 1, 0]. Centers0and1both reach 4, and1is the larger of the two.
Example 2
centerCapacity = [1,2,4,2,1]dailyLogs = ["PACKAGE","PACKAGE","CLOSED 2","PACKAGE","PACKAGE","PACKAGE","PACKAGE","CLOSED 1","PACKAGE","PACKAGE"]return = 3- Package 1 fills center
0, and package 2 goes to center1. CLOSED 2takes center2out of service before it gets anything. The round keeps going: package 3 fills center1, center2is passed over, packages 4 and 5 fill center3, and package 6 fills center4.CLOSED 1then takes center1out of service. Its 2 packages stay in its total.- Package 7 starts round 2 at center
0. Every center gets its room back, but centers1and2stay out of service, so package 8 goes to center3. - Final counts:
[2, 2, 0, 3, 1], so the answer is3.
Example 3
centerCapacity = [1,4,2,2]dailyLogs = ["PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","PACKAGE","CLOSED 1"]return = 1- Round 1 uses all 9 slots: centers
0to3take 1, 4, 2 and 2 packages. - Round 2: center
0takes package 10 and center1takes package 11. - The last entry,
CLOSED 1, comes after every package, and center1keeps all 5 of its packages. - Final counts:
[2, 5, 2, 2], so the answer is1, a center that is closed at the end.
Constraints
1 <= centerCapacity.length <= 10001 <= centerCapacity[j] <= 51 <= dailyLogs.length <= 10^4- Allowed entries:
"PACKAGE", and"CLOSED j"with0 <= j < centerCapacity.lengthwritten in decimal without leading zeros. - A center number appears in at most one
"CLOSED"entry, and the"CLOSED"entries name fewer thancenterCapacity.lengthcenters.
More Capital One Online Assessment questions
- Branch with the Most FilesOA · Seen Nov 2026
- Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
- Earn the Most 🐝OA · Seen Nov 2026
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Arithmetic Triplets After QueriesOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions
- Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences