Reported July 2026
DRWunion find

Doctor Appointment Slot Assignment

Reported by candidates from DRW's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live DRW OA. Under 2s to a working solution.
Founder's read

The DRW OA reported in July 2026 gives you patients with exactly two preferred slots each, like A = [1,1,3] and B = [2,2,1] with S = 3. Can everyone get a unique slot? It looks like matching, and it looks scary. It isn't. Treat slots as nodes and patients as edges, and the problem collapses into a graph check you've probably seen before. If you blank on the reframe during the assessment, StealthCoder runs invisibly as a desktop overlay and can hand you the approach in real time. Here's the trick so you don't need it.

The problem

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 = 3
return = 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 = 3
return = 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 = 8
return = 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 = 10
return = 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].

Reported by candidates. Source: FastPrep

Pattern and pitfall

Each patient is an edge between slot A[K] and slot B[K]. Assigning a patient to a slot means orienting that edge toward one endpoint, and each node can receive at most one edge. So for every connected component, you need edges <= nodes. A tree component (edges = nodes - 1) works. A component with exactly one cycle works (edges = nodes). Anything with more edges than nodes fails. Use union-find: track node count and edge count per component, then check each one. The common pitfall is trying bipartite matching or backtracking, which is too slow at N up to 100000. Another pitfall is forgetting that slots nobody wants are just isolated nodes and don't matter. Example 2 fails quickly since 4 edges sit on 3 nodes. If the reframe slips your mind live, StealthCoder is the hedge that surfaces it while you keep typing.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Doctor Appointment Slot Assignment cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass DRW's OA.

DRW reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Doctor Appointment Slot Assignment FAQ

What's the trick to the DRW doctor appointment slot problem?+

Model slots as graph nodes and patients as edges connecting their two preferred slots. Assigning a patient means picking one endpoint of that edge. Each node can be picked once, so every connected component needs edges less than or equal to nodes. That's the whole check.

Which data structure should I use?+

Union-find is the cleanest. Union A[K] and B[K] for every patient, then count nodes and edges per root. Alternatively, run DFS per component and count. Both are near-linear, which fits N and S up to 100000 comfortably.

Why not just use bipartite matching?+

Matching works in theory but it's heavier than needed. With two choices per patient, the graph structure gives you a simple edge-versus-node count. Backtracking or flow risks timeouts at 100000. The component counting check is simpler and faster to write under pressure.

How hard is this problem really?+

The code is short, maybe 25 lines with union-find. The difficulty is seeing the graph model. Once you see patients as edges, it's easy. Candidates who don't see it usually try greedy assignment and fail on cycles.

How do I prepare in 48 hours?+

Practice the pseudoforest idea: a component is fine if it has at most one cycle. Write union-find with per-root counters for nodes and edges from scratch. Then trace Example 2 and Example 4 by hand to confirm why they return false.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with DRW.

OA at DRW?
Invisible during screen share
Get it