FastPrepEvenly Schedule Vehicle Inspections

Evenly Schedule Vehicle Inspections

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Vehicles require inspection registration every six months. A registration office closes on holidays. Its standard daily window is 10 a.m. to 4 p.m., and each vehicle takes one one-hour slot. A reported follow-up changes the window to 11 a.m. to 3 p.m.

For this exercise, schedule one waiting batch of n vehicles within a planning horizon of dayCount consecutive days numbered from 0. The array holidays contains closed day numbers. All other days are open, and each open day has slots starting at the integer hours openHour, openHour + 1, and so on up to but not including closeHour. The interval [openHour, closeHour) represents either the standard window or the follow-up window.

Fair distribution

Assign each vehicle exactly one slot. Distribute the vehicles as evenly as possible across all open days: the numbers assigned to any two open days must differ by at most one. If some days must receive one extra vehicle, give those extras to the earlier open days. Within a day, use the earliest available slots first.

Return an int[][] of [day, startHour] pairs in increasing day and hour order. Vehicle i receives the pair at index i. The input is guaranteed to have enough available slots.

Function

scheduleVehicleInspections(n: int, dayCount: int, holidays: int[], openHour: int, closeHour: int) → int[][]

Examples

Example 1

n = 8dayCount = 3holidays = [1]openHour = 10closeHour = 16return = [[0,10],[0,11],[0,12],[0,13],[2,10],[2,11],[2,12],[2,13]]

Day 1 is closed. The eight vehicles split evenly between open days 0 and 2, so each receives four registrations using its first four hourly slots.

Example 2

n = 5dayCount = 4holidays = [1]openHour = 11closeHour = 15return = [[0,11],[0,12],[2,11],[2,12],[3,11]]

The follow-up window has four one-hour slots per open day. Five vehicles across open days 0, 2, and 3 give loads of 2, 2, and 1. The earlier two days receive the extra vehicles.

Example 3

n = 0dayCount = 2holidays = [0]openHour = 10closeHour = 16return = []

No vehicles are waiting, so the schedule is empty.

Constraints

  • 0 <= n <= 4,416.
  • 1 <= dayCount <= 184.
  • Each value in holidays is unique and between 0 and dayCount - 1.
  • 0 <= openHour < closeHour <= 24; every slot lasts one hour.
  • The number of available slots across all open days is at least n.

More Amazon problems

See Amazon hiring insights
public int[][] scheduleVehicleInspections(int n, int dayCount, int[] holidays, int openHour, int closeHour) {
    // Write your code here
}
n8
dayCount3
holidays[1]
openHour10
closeHour16
expected[[0,10],[0,11],[0,12],[0,13],[2,10],[2,11],[2,12],[2,13]]
Checking account…