Worker Management, Part 2: Top Workers
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Anthropic OA from July 2026 hands you Part 2 of a worker management system, and the trap is in the sort, not the data structure. You already have ADD_WORKER, REGISTER and GET from Part 1. Now TOP_N_WORKERS wants workers at a position, ranked by completed session time descending, then worker ID ascending. It's a simulation problem with a hash map and a custom sort. If you blank on the details live, StealthCoder runs invisibly as a safety net, but the logic here is short enough to own.
The problem
Continue the worker management system from Part 1. ADD_WORKER, REGISTER, and GET keep the same behavior. New Operation ["TOP_N_WORKERS", n, position]: return up to n workers whose current position equals position. Rank by total time from completed office sessions in descending order, then by worker ID in ascending alphabetical order. Format the result as workerId1(time1), workerId2(time2),.... A worker with no completed session has time 0. Return an empty string when no worker has the requested position. Function workerManagementLevel2(operations: String[][]) → String[] Examples Example 1 operations = [["ADD_WORKER","John","Junior Developer","120"],["ADD_WORKER","Jason","Junior Developer","120"],["ADD_WORKER","Ashley","Junior Developer","120"],["REGISTER","John","100"],["REGISTER","John","150"],["REGISTER","Jason","200"],["REGISTER","Jason","250"],["REGISTER","Jason","275"],["TOP_N_WORKERS","5","Junior Developer"],["TOP_N_WORKERS","1","Junior Developer"],["REGISTER","Ashley","400"],["REGISTER","Ashley","500"],["REGISTER","Jason","575"],["TOP_N_WORKERS","3","Junior Developer"],["TOP_N_WORKERS","3","Middle Developer"]] return = ["true","true","true","registered","registered","registered","registered","registered","Jason(50), John(50), Ashley(0)","Jason(50)","registered","registered","registered","Jason(350), Ashley(100), John(50)",""] Jason and John initially tie at 50, so Jason comes first alphabetically. Jason's session from 275 to 575 later raises his total to 350.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a map from worker ID to position, total completed time, and the open session start. REGISTER toggles: the first call opens a session, the second closes it and adds the difference to the total. The example shows this, since John's 100 and 150 give 50. The common mistake is counting an open session as time. Jason's 275 stays open until 575, so he sits at 50 in the earlier query and jumps to 350 later. Only completed sessions count. For TOP_N_WORKERS, filter by position, sort by negative time then ID, take the first n, and format as id(time) joined by comma and space. Return an empty string if nobody matches. Sorting per query is fine unless the input is huge. Watch the output separator, because the expected format has a space after each comma. StealthCoder is your hedge on the live OA if the Part 1 behavior slips your mind.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Worker Management, Part 2: Top Workers 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Worker Management, Part 2: Top Workers FAQ
What's the trick in Worker Management Part 2?+
Only completed sessions count toward time. A REGISTER call that opens a session adds nothing until the next REGISTER closes it. Then sort by time descending and ID ascending. Most failed attempts count open sessions or get the tie-break wrong.
How hard is this Anthropic OA question really?+
Easy on algorithms, annoying on details. It's simulation with a hash map and a custom comparator. The difficulty is carrying Part 1 behavior forward without breaking it and matching the exact output format.
How should the output string be formatted?+
Each entry is workerId(time), joined with a comma and a space, like Jason(50), John(50), Ashley(0). If no worker holds the requested position, return an empty string, not null or a placeholder.
What happens when n is larger than the number of workers?+
You return up to n, so just return everyone at that position. The first example asks for 5 with only 3 workers and gets all 3. Slice safely with a min of n and the list length.
How do I prepare for this in 48 hours?+
Write a small class with a worker map, a toggle for REGISTER, and a sort with a two-key comparator. Run the example by hand, especially the Jason 275 to 575 case. Practice parsing string operations into typed arguments, since every input arrives as strings.