Oscar Health logoOscar Health
CodingFree preview

Provider Network Coverage Check

Given providers (specialties + (x, y) location), members (required specialties + location) and a max distance, return members lacking adequate access: a member is covered only if every required specialty has some provider within Euclidean max distance. Field shapes vary slightly between loops (single specialty vs list).

SWE
geometry
hashmap
array
domain-knowledge
Frequency
Low
Last asked
2026-07-23
Stage
onsite-coding

Problem

The goal is for every member to reach an in-network provider of each specialty they need (e.g. Cardiology, Dermatology) within a set travel distance. Given a list of providers, a list of members (clients), and a maximum distance, return the IDs of members who lack adequate network access — i.e. who are outside the coverage area.

  • Provider: id, one or more specialties, location as an (x, y) point.
  • Member / client: id, one or more required specialties, location as an (x, y) point.
  • Distance: Euclidean (the standard distance-between-two-points formula).

Constraints given in the prompt:

  1. A provider can offer more than one specialty.
  2. More than one client / provider can be at the same location.
  3. A client can have more than one requirement.
  4. A client is outside the coverage area unless every specialty they need is offered by some provider within the maximum distance. Different requirements may be satisfied by different providers.

Examples

providers = [
    {"id": 1, "specialty": "Cardiology", "location": (1, 2)},
    {"id": 2, "specialty": "Dermatology", "location": (3, 4)},
]
members = [
    {"id": 101, "location": (2, 3), "required_specialties": ["Cardiology", "Dermatology"]},
    {"id": 102, "location": (10, 10), "required_specialties": ["Cardiology"]},
]
max_distance = 5

# Output: [102]
# 101: Cardiology at sqrt(2) ≈ 1.41, Dermatology at sqrt(2) ≈ 1.41 -> covered
# 102: nearest Cardiology at sqrt(145) ≈ 12.04 -> not covered

Variants

String IDs with specialty lists

Another loop uses string IDs, providers with multiple specialties, and max distance 3:

Providers: String providerId, String[] specialities, Location location
{101, ["ortho","cardio","pedi"], [1,2]}
{102, ["pedi"], [3,4]}
{103, ["ortho","cardio","pedi"], [1,8]}
{104, ["ortho"], [4,2]}
{105, ["ortho","pedi"], [5,1]}

Clients: String clientId, String[] requirements, Location location
{201, ["ortho","cardio"], [4,1]}
{202, ["ortho"], [3,2]}
{203, ["pedi"], [5,5]}
{204, ["ortho","pedi"], [2,2]}
{205, ["cardio"], [3,3]}

max distance: 3

Hints

Pitfalls

  • A member with several requirements is covered only if each requirement has an in-range provider — not just one of them, and not necessarily the same provider for all.
  • Field shape varies between loops: one version gives each provider a single specialty string, another gives a specialities list. Clarify before coding and write the lookup so it handles a list.
  • Confirm whether a provider exactly at max_distance counts as in range (<= vs <), and compare squared distances if you want to avoid floating-point square roots.
  • Co-located providers and members are explicitly allowed; do not key any map by location alone.
  • Return member IDs, not member objects — the prompt asks for IDs.

Talking Points

  • Grouping by specialty is the biggest single win: it restricts each check to relevant providers.
  • Squared-distance comparison is exact and cheaper than sqrt, and sidesteps rounding at boundary distances.
  • Early termination at both loop levels shows you think about average case, not only worst case.
  • Handle a required specialty with zero providers explicitly — that member is immediately uncovered.
  • Name spatial structures (k-d tree, R-tree, geohash grid) for scale even if you do not implement them.

Follow-ups

Preparation

  • Implement the brute-force version (for each member, for each requirement, scan providers) and state its complexity.
  • Then index providers by specialty so each requirement only scans relevant providers; be ready to explain the speedup.
  • Run both sample datasets by hand and check the first one returns [102].
  • Swap the distance function for haversine and confirm only the distance helper changes.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...