Problem · Array
Future-Effective Employee Salary
Learn this problemProblem statement
Simulate an effective-dated employee salary API over a finite ordered sequence of operations. Operation i uses operations[i], employeeIds[i], requestTimes[i], effectiveTimes[i], and salaryValues[i]. Request times are nondecreasing.
Operations
ADD: add a new employee with salarysalaryValues[i]effective atrequestTimes[i]. For this operation,effectiveTimes[i]equalsrequestTimes[i]. Return-1.SCHEDULE: register salarysalaryValues[i]for an existing employee at the future timeeffectiveTimes[i], whereeffectiveTimes[i] > requestTimes[i]. Return-1.GET: query the employee's salary ateffectiveTimes[i]. IgnoresalaryValues[i]. Among versions submitted by earlier operations, return the salary with the greatest effective timestamp not after the query timestamp.
If a later SCHEDULE uses the same employee and effective timestamp as an earlier one, the later value replaces the earlier value for subsequent operations. A GET for an unknown employee, or for a time before that employee's first effective salary, returns -1.
Return one integer for every operation, in input order.
Function
applySalaryOperations(operations: String[], employeeIds: String[], requestTimes: int[], effectiveTimes: int[], salaryValues: int[]) → int[]Examples
Example 1
operations = ["ADD","SCHEDULE","GET","GET","GET"]employeeIds = ["e1","e1","e1","e1","e1"]requestTimes = [1,2,3,3,3]effectiveTimes = [1,10,5,10,12]salaryValues = [100,150,0,0,0]return = [-1,-1,100,150,150]The salary is 100 before time 10 and 150 from time 10 onward.
Example 2
operations = ["ADD","SCHEDULE","SCHEDULE","GET"]employeeIds = ["e","e","e","e"]requestTimes = [1,2,3,4]effectiveTimes = [1,10,10,10]salaryValues = [80,100,120,0]return = [-1,-1,-1,120]The second schedule replaces the first version at effective time 10, so the query returns 120.
Constraints
1 <= operations.length <= 200000.- All five input arrays have the same length.
- Each operation is
ADD,SCHEDULE, orGET. 0 <= requestTimes[i], effectiveTimes[i] <= 10^9, and request times are nondecreasing.- Every
ADDuses a unique nonempty employee ID and haseffectiveTimes[i] == requestTimes[i]. - Every
SCHEDULEnames an existing employee and haseffectiveTimes[i] > requestTimes[i]. 1 <= salaryValues[i] <= 10^9forADDandSCHEDULE.