FastPrepDoctor Appointment Slot Assignment
Problems/Doctor Appointment Slot Assignment

Doctor Appointment Slot Assignment

DRW logoDRW● MediumOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem 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) → boolean

Examples

Example 1

A = [1,1,3]B = [2,2,1]S = 3return = true

One 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 = false

There 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 = true

One 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 = false

It is not possible to assign all patients to preferred slots while keeping at most one patient in each slot.

Constraints

  • N is an integer within the range [1, 100000].
  • S is an integer within the range [2, 100000].
  • Each element of arrays A and B is an integer within the range [1, S].
  • No patient has two preferences for the same slot, i.e. A[i] != B[i].

More DRW Online Assessment questions

  • Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
  • Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
  • Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
  • 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
  • Nested In-Memory Database TransactionsOA · Seen Aug 2026
  • Password Requirement CheckOA · Seen Aug 2026
  • Remove Excess Consecutive CharactersOA · Seen Aug 2026
  • Last Round for Each PlayerOA · Seen Jul 2026
  • Shortest Compressed Length After RemovalOA · Seen Jul 2026
  • Maximum Even-Sum Neighboring PairsOA · Seen Jul 2026

Similar questions at other companies

  • Minimum Cost to Supply Water with Wells and PipesInfosys · OAInfosys interview questions
  • Minimum Cost for Roads and HospitalsAmazon · ONSITE INTERVIEW
  • Maximum Edge Removals for Two TravelersMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Water Supply With Wells and PipesNutanix · ONSITE INTERVIEWNutanix interview questions
  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
  • Maximum K-Star SumC3.ai · OAC3.ai interview questions
  • Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
  • Optimal TransferSnowflake · OASnowflake interview questions
  • Minimum Unreachable WarehousesVisa · OAVisa interview questions
  • Connected Components with Divisor ThresholdInMobi · OAInMobi interview questions
All DRW interview questionsSee DRW hiring insights
Saved
class Solution {
    public boolean solution(int[] A, int[] B, int S) {
      // write your code here
    }
}
Checking account…