Find the earliest semantic version that supports all required features

Quick Overview

Given software versions in major.minor.patch form and the features each version supports, find the earliest version that supports every required feature. It tests numeric semantic version comparison, subset checks with sets, and careful handling of ties and empty inputs.

Find the earliest semantic version that supports all required features

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given a list of software `versions`, where each version follows semantic versioning in the format `major.minor.patch` (for example `"1.2.3"`). You are also given a list `features`, where `features[i]` is the list of feature names supported by `versions[i]`. Finally, you are given a list `required_features` of the features that must all be supported. Return the earliest version (by semantic version ordering) that supports all of the required features. Semantic version ordering compares the major version first, then minor, then patch. If no version supports all required features, return an empty string `""`. ### Function Signature ```python def find_earliest_version(versions: list[str], features: list[list[str]], required_features: list[str]) -> str: ``` ### Rules - `major`, `minor` and `patch` are each compared as integers, so `"1.10.0"` is later than `"1.9.0"`. - A version qualifies when every name in `required_features` appears in its feature list. Extra features are allowed, and a name listed more than once counts once. - If `required_features` is empty, every version qualifies. - Return the version string exactly as it appears in `versions`. If two qualifying entries compare equal, return the one with the smaller index. ### Constraints - `1 <= versions.length <= 10^4` - `versions.length == features.length` - Each version string has the format `major.minor.patch`, where `major`, `minor` and `patch` are non-negative integers. - `0 <= features[i].length <= 100` - `0 <= required_features.length <= 100` - Feature names consist of lowercase English letters, digits and hyphens. ### Examples ```text Input: versions = ["2.0.0", "1.3.0", "1.2.5", "1.4.0"], features = [["auth", "logging", "cache"], ["auth", "logging"], ["auth", "cache"], ["auth", "logging", "cache", "metrics"]], required_features = ["auth", "logging", "cache"] Output: "1.4.0" ``` Versions 2.0.0 and 1.4.0 both support auth, logging and cache (the extra metrics feature in 1.4.0 is allowed). 1.4.0 has the smaller major version, so it is the earlier of the two. ```text Input: versions = ["0.1.0", "0.2.0", "0.2.1"], features = [["beta"], ["beta", "gamma"], ["beta", "delta"]], required_features = ["beta", "gamma", "delta"] Output: "" ``` No version has all three features: 0.2.0 lacks delta and 0.2.1 lacks gamma, so the answer is the empty string. ```text Input: versions = ["1.10.0", "1.9.12", "1.9.0"], features = [["sso", "audit"], ["sso"], ["audit"]], required_features = ["sso"] Output: "1.9.12" ``` 1.10.0 and 1.9.12 qualify, and 1.9.0 does not because it lacks sso. Minor version 9 is less than 10, so 1.9.12 is earlier, even though plain string comparison would put `"1.10.0"` first.

Overview: Given software versions in major.minor.patch form and the features each version supports, find the earliest version that supports every required feature. It tests numeric semantic version comparison, subset checks with sets, and careful handling of ties and empty inputs.

OpenAI logo
OpenAI
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of software versions, where each version follows semantic versioning in the format major.minor.patch (for example "1.2.3"). You are also given a list features, where features[i] is the list of feature names supported by versions[i]. Finally, you are given a list required_features of the features that must all be supported.

Return the earliest version (by semantic version ordering) that supports all of the required features. Semantic version ordering compares the major version first, then minor, then patch.

If no version supports all required features, return an empty string "".

Function Signature

def find_earliest_version(versions: list[str], features: list[list[str]], required_features: list[str]) -> str:

Rules

  • major , minor and patch are each compared as integers, so "1.10.0" is later than "1.9.0" .
  • A version qualifies when every name in required_features appears in its feature list. Extra features are allowed, and a name listed more than once counts once.
  • If required_features is empty, every version qualifies.
  • Return the version string exactly as it appears in versions . If two qualifying entries compare equal, return the one with the smaller index.

Constraints

  • 1 <= versions.length <= 10^4
  • versions.length == features.length
  • Each version string has the format major.minor.patch , where major , minor and patch are non-negative integers.
  • 0 <= features[i].length <= 100
  • 0 <= required_features.length <= 100
  • Feature names consist of lowercase English letters, digits and hyphens.

Examples

Input: versions = ["2.0.0", "1.3.0", "1.2.5", "1.4.0"], features = [["auth", "logging", "cache"], ["auth", "logging"], ["auth", "cache"], ["auth", "logging", "cache", "metrics"]], required_features = ["auth", "logging", "cache"]
Output: "1.4.0"

Versions 2.0.0 and 1.4.0 both support auth, logging and cache (the extra metrics feature in 1.4.0 is allowed). 1.4.0 has the smaller major version, so it is the earlier of the two.

Input: versions = ["0.1.0", "0.2.0", "0.2.1"], features = [["beta"], ["beta", "gamma"], ["beta", "delta"]], required_features = ["beta", "gamma", "delta"]
Output: ""

No version has all three features: 0.2.0 lacks delta and 0.2.1 lacks gamma, so the answer is the empty string.

Input: versions = ["1.10.0", "1.9.12", "1.9.0"], features = [["sso", "audit"], ["sso"], ["audit"]], required_features = ["sso"]
Output: "1.9.12"

1.10.0 and 1.9.12 qualify, and 1.9.0 does not because it lacks sso. Minor version 9 is less than 10, so 1.9.12 is earlier, even though plain string comparison would put "1.10.0" first.