Doctor Appointment Slot Assignment
Learn this problemProblem statement
There are N patients, numbered from 0 to N - 1, who want to visit the doctor. The doctor has S possible appointment slots, numbered from 1 to S.
Each patient has two preferred slots. Patient K would like to visit the doctor during either slot A[K] or slot B[K].
The doctor can treat only one patient during each slot.
Return whether it is possible to assign every patient to one of their preferred slots so that at most one patient is assigned to each slot.
Function
solution(A: int[], B: int[], S: int) → booleanExamples
Example 1
A = [1,1,3]B = [2,2,1]S = 3return = trueOne valid assignment is [1,2,3], where the K-th element is the slot assigned to patient K. Another valid assignment is [2,1,3].
Example 2
A = [3,2,3,1]B = [1,3,1,2]S = 3return = falseThere are four patients but only three slots, so at least two patients would have to share a slot.
Example 3
A = [2,5,6,5]B = [5,4,2,2]S = 8return = trueOne valid assignment is [5,4,6,2].
Example 4
A = [1,2,1,6,8,7,8]B = [2,3,4,7,7,8,7]S = 10return = falseIt is not possible to assign all patients to preferred slots while keeping at most one patient in each slot.
Constraints
Nis an integer within the range[1, 100000].Sis an integer within the range[2, 100000].- Each element of arrays
AandBis an integer within the range[1, S]. - No patient has two preferences for the same slot, i.e.
A[i] != B[i].