Find earliest supporting dependency version
Company: OpenAI
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
##### Question
Given a list of dependency versions (e.g. [103.003.02, 103.003.03, 203.003.02]) and a black-box API isSupported(v), design an algorithm to find the earliest (lowest) version that supports a target feature.
2) Versions follow {major}.{minor}.{patch}. Support is not monotonic: a higher version may drop support, but it is guaranteed that some later version will support again. The API is rate-limited, so total calls must be sub-linear to the number of versions. Devise a strategy—e.g., group by latest patch per major, binary-search majors, then minors, then patches—to minimize API usage while reliably returning the earliest supporting version.
Quick Answer: This question evaluates a candidate's ability to design efficient search algorithms and reason about algorithmic complexity under constraints such as non-monotonic predicate behavior and a rate-limited black-box API.
You are given a sorted list of distinct dependency versions in the form "major.minor.patch" and a simulated black-box API isSupported(v). Your task is to return the earliest version that supports a target feature. Global support is not monotonic at the full version level: for example, one version may support the feature, a later version from a new major or minor may not, and an even later version may support again. To make sub-linear API usage possible, the data obeys these guarantees: (1) there is a first major that contains any supporting version, and every later major also contains at least one supporting version; (2) inside that first supporting major, there is a first minor that contains any supporting version, and every later minor in that major also contains at least one supporting version; (3) inside that first supporting major/minor pair, support is monotonic by patch among the listed versions. Also, if a major or minor contains any supporting version, its latest listed version is guaranteed to be supporting. For this coding task, supported_versions simulates the API: version v supports the feature if and only if v is present in supported_versions. Return the earliest supporting version, or None if no version supports the feature.
Constraints
- 0 <= len(versions) <= 200000
- versions is sorted in ascending semantic-version order, all versions are distinct, and supported_versions is a subset of versions
- The support pattern obeys the hierarchical guarantees described above: a first supporting major exists if support exists at all; within it, a first supporting minor exists; within it, a first supporting patch exists; and the latest listed version of any supporting major or minor is also supporting