Find earliest supporting version under constraints
Company: OpenAI
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates parsing and comparison of zero-padded version strings, handling of invalid inputs and duplicates, and design of rate-limited search strategies with complexity analysis, reflecting skills in robust input handling, algorithmic thinking, and system-aware optimization.
Part 1: Earliest Supporting Version in an Arbitrary List
Constraints
- 0 <= len(versions) <= 200000
- 0 <= len(supported_versions) <= 200000
- A valid version has exactly 3 non-empty numeric segments separated by dots
- Leading zeros are allowed and do not affect ordering
- Invalid version strings must be ignored
Examples
Input: (["103.003.03", "103.003.02", "102.010.009"], ["103.003.02", "102.010.009"])
Expected Output: "102.10.9"
Explanation: Both listed versions support the feature, and `(102, 10, 9)` is smaller than `(103, 3, 2)`.
Input: (["001.002.003", "1.2.3", "bad", "1.2", "01.002.004"], ["0001.0002.0003", "99.0.0"])
Expected Output: "1.2.3"
Explanation: Invalid entries are ignored. `001.002.003` and `1.2.3` are the same numeric version, which is supported.
Input: (["1.0.0", "2.0.0"], ["3.0.0"])
Expected Output: None
Explanation: No supporting version appears in the given list.
Input: ([], ["0.0.1"])
Expected Output: None
Explanation: Edge case: empty version list.
Input: (["007.000.009"], ["7.0.9"])
Expected Output: "7.0.9"
Explanation: Single valid version, with zero padding.
Hints
- Parse every valid version into a tuple of three integers so numeric comparison becomes easy.
- Because support is not monotonic, scanning the list and tracking the minimum supporting version is enough; binary search does not apply.
Part 2: Earliest Supporting Version with Sublinear Support Checks
Constraints
- 0 <= len(versions) <= 200000
- 0 <= len(supported_versions) <= 200000
- A valid version has exactly 3 non-empty numeric segments separated by dots
- Leading zeros are allowed and do not affect ordering
- The monotone representative guarantees listed above hold for all valid test cases
- Invalid version strings must be ignored
Examples
Input: (["1.0.0", "1.0.1", "2.0.0", "2.0.1", "2.1.0", "2.1.1", "3.0.0", "3.0.1"], ["2.0.1", "2.1.1", "3.0.1"])
Expected Output: "2.0.1"
Explanation: The first supporting major is 2, the first supporting minor inside major 2 is 0, and the first supporting patch there is 1.
Input: (["1.0.0", "1.0.1", "1.0.2", "1.1.0", "1.1.1", "2.0.0", "2.0.1"], ["1.0.1", "1.0.2", "1.1.1", "2.0.1"])
Expected Output: "1.0.1"
Explanation: Major 1 already supports the feature. Inside major 1, minor 0 supports before minor 1, and within minor 0 the first supporting patch is 1.
Input: (["1.0.0", "1.0.1", "2.0.0"], [])
Expected Output: None
Explanation: Edge case: no supporting version exists.
Input: (["007.000.009"], ["7.0.9"])
Expected Output: "7.0.9"
Explanation: Edge case: single valid version.
Input: (["bad", "01.002.000", "1.2.1", "1.3.0", "1.3.1", "2.0.0", "2.0.1", "1.2.0", "1.2.1"], ["001.002.001", "1.3.1", "2.0.1"])
Expected Output: "1.2.1"
Explanation: Invalid entries and duplicates are ignored. The earliest supporting version is `1.2.1`.
Hints
- Precompute the latest version in each major and the latest version in each minor of a major.
- Run three lower-bound style binary searches: one over majors, one over minors in the chosen major, and one over patches in the chosen minor.