Problem
Implement outside_coverage(providers, clients, max_distance).
Each provider has an id, a list of specialties, and a two-dimensional location = [x, y]. Each client has an id, a list of required specialties in requirements, and a two-dimensional location. A required specialty is covered when at least one provider offering that specialty is within Euclidean distance max_distance of the client. Different requirements may be covered by different providers.
Return the IDs of clients for which at least one required specialty is not covered. Preserve client input order.
Constraints
-
Up to
2,000
providers and
2,000
clients
-
Coordinates and
max_distance
are finite numbers;
max_distance >= 0
-
Specialty strings within one record are unique.
-
Multiple providers or clients may share a location.
-
Distance exactly equal to
max_distance
is covered.
Example
Providers:
P1: specialties=[cardio, ortho], location=[0, 0]
P2: specialties=[pedi], location=[5, 0]
Clients:
C1: requirements=[ortho], location=[1, 0]
C2: requirements=[ortho, pedi], location=[1, 0]
C3: requirements=[pedi], location=[4, 0]
With max_distance = 2, return [C2].
Hint
Compare squared distances to avoid unnecessary square roots. Correctness requires checking every required specialty, not merely finding one nearby provider.
Interview Follow-ups
-
Index providers to support many repeated queries.
-
Explain how the design changes in geographic coordinates rather than a flat plane.
-
Return the missing specialties for each uncovered client.