Problem · Hash Table

Worker Management, Part 4: Double-Paid Intervals

Learn this problem
HardAnthropicOA

Problem statement

Continue the worker management system from Part 3. Existing worker, session, promotion, ranking, and salary operations keep their behavior.

Double-Paid Time

  • ["SET_DOUBLE_PAID", start_timestamp, end_timestamp]: register the half-open interval [start_timestamp, end_timestamp) as double-paid time and return an empty string.
  • Double-paid intervals apply globally to every worker.
  • Merge overlapping intervals. Time covered by multiple registered intervals is still paid at most twice, never three or more times.
  • CALC_SALARY first pays normal compensation for completed-session time, then adds one extra copy of compensation for the portion inside double-paid intervals.

Function

workerManagementLevel4(operations: String[][]) → String[]

Examples

Example 1

operations = [["ADD_WORKER","Alice","Engineer","100"],["REGISTER","Alice","10"],["REGISTER","Alice","30"],["SET_DOUBLE_PAID","15","25"],["CALC_SALARY","Alice","0","40"],["SET_DOUBLE_PAID","20","35"],["CALC_SALARY","Alice","0","40"]]return = ["true","registered","registered","","3000","","3500"]

Alice's completed session pays 20*100 = 2000 normally. The first double-paid interval overlaps it for 10 units, producing 3000. After merging [15,25) with [20,35), the session has 15 double-paid units, producing 3500.

More Anthropic problems

drafts saved locally
public String[] workerManagementLevel4(String[][] operations) {
  // write your code here
}
operations[["ADD_WORKER","Alice","Engineer","100"],["REGISTER","Alice","10"],["REGISTER","Alice","30"],["SET_DOUBLE_PAID","15","25"],["CALC_SALARY","Alice","0","40"],["SET_DOUBLE_PAID","20","35"],["CALC_SALARY","Alice","0","40"]]
expected["true", "registered", "registered", "", "3000", "", "3500"]
checking account