Problem · Hash Table

Worker Management, Part 2: Top Workers

Learn this problem
MediumAnthropicOA

Problem statement

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.

More Anthropic problems

drafts saved locally
public String[] workerManagementLevel2(String[][] operations) {
  // write your code here
}
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"]]
expected["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)", ""]
checking account