Problem · Array

Future-Effective Employee Salary

Learn this problem
MediumRippling logoRipplingFULLTIMEONSITE INTERVIEW

Problem 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 salary salaryValues[i] effective at requestTimes[i]. For this operation, effectiveTimes[i] equals requestTimes[i]. Return -1.
  • SCHEDULE: register salary salaryValues[i] for an existing employee at the future time effectiveTimes[i], where effectiveTimes[i] > requestTimes[i]. Return -1.
  • GET: query the employee's salary at effectiveTimes[i]. Ignore salaryValues[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, or GET.
  • 0 <= requestTimes[i], effectiveTimes[i] <= 10^9, and request times are nondecreasing.
  • Every ADD uses a unique nonempty employee ID and has effectiveTimes[i] == requestTimes[i].
  • Every SCHEDULE names an existing employee and has effectiveTimes[i] > requestTimes[i].
  • 1 <= salaryValues[i] <= 10^9 for ADD and SCHEDULE.

More Rippling problems

drafts saved locally
public int[] applySalaryOperations(String[] operations, String[] employeeIds, int[] requestTimes, int[] effectiveTimes, int[] salaryValues) {
    // Write your code here.
}
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]
expected[-1,-1,100,150,150]
checking account