Problem · Array
Filter and Sort Scheduled Tasks
Learn this problemProblem statement
Given parallel arrays describing scheduled tasks and a current timestamp, return the IDs of all eligible tasks in execution order.
A task at index i is eligible exactly when:
statuses[i]isPENDING; andscheduledTimes[i]is at mostcurrentTime.
Sort eligible tasks by:
priorities[i]descending;scheduledTimes[i]ascending; thentaskIds[i]lexicographically ascending.
Return the ordered task IDs. The judged practice combines the reported filtering and sorting capabilities into one result; it does not invent a separate undisclosed third part.
Function
filterAndSortTasks(taskIds: String[], scheduledTimes: long[], priorities: int[], statuses: String[], currentTime: long) → String[]Examples
Example 1
taskIds = ["task-a","task-b","task-c","task-d"]scheduledTimes = [10,5,10,1]priorities = [2,3,3,9]statuses = ["PENDING","PENDING","RUNNING","PENDING"]currentTime = 10return = ["task-d","task-b","task-a"]task-c is not pending. The other tasks are due, so priority places task-d first, followed by task-b and task-a.
Example 2
taskIds = ["z","a","b","late"]scheduledTimes = [7,7,3,11]priorities = [5,5,5,9]statuses = ["PENDING","PENDING","PENDING","PENDING"]currentTime = 7return = ["b","a","z"]late is not due. The other tasks have equal priority, so the earlier timestamp places b first and the lexicographic tie-break places a before z.
Example 3
taskIds = ["done","future"]scheduledTimes = [1,100]priorities = [10,10]statuses = ["COMPLETED","PENDING"]currentTime = 50return = []The completed task is ineligible and the pending task is not due, so the result is empty.
Constraints
0 <= taskIds.length <= 10^5.- All four task arrays have the same length.
- Task IDs are unique non-empty strings.
- Each timestamp fits in a signed
64-bit integer and each priority fits in a signed32-bit integer. - Every status is
PENDING,RUNNING, orCOMPLETED.
More Rippling problems
- Stateful Log Transform and SearchPHONE SCREEN · Seen Jul 2026
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Aug 2025