BLOGLLM Logo
Go Pro
Guest
Not signed in
All BlogsCoursesPracticeInterview prepSeriesTagsBookmarksPricing
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboardGames
Articles
Practice / MLOps23 of 26 in topic

780. CI matrix: find the newest runtime version your package supports

MediumMLOps Pro

Your library's CI must answer: what is the newest Python (or CUDA, or Node) version this release still works on? Each check builds a fresh environment and runs the test suite, which takes minutes, so you want as few checks as possible. Support is monotone: every version up to some cutoff works and every newer one fails (newer runtimes removed an API you use). That makes it a binary search, once the versions are in the right order.

Write newest_supported(versions, supports).
- versions: a list of distinct version strings such as '3.9', '3.10', '2.7.18' or '12.4', in no particular order (they come from a config file).
- supports(v): runs the slow check and returns True for every version up to the cutoff and False for every newer one.

Ordering rules: compare part by part as integers, so '3.10' is newer than '3.9' (a plain string sort gets this wrong, and so does float('3.10') == 3.1). A missing part counts as 0, so '3.7' is older than '3.7.1'.

Return the newest version for which supports returns True, or None if none is supported or versions is empty.

Budget: call supports at most ceil(log2(n)) + 1 times for n versions. Checking every version one by one is not allowed.

Functiondef newest_supported(versions, supports)

Example 1

Input: versions = ['3.10', '3.8', '3.9', '3.11', '3.12'] and supports

Output: True up to '3.10' returns '3.10'

Example 2

Input: versions = ['1.0', '0.9'] and supports always

Output: False returns None

Constraints

  • 1 <= n <= 100,000 versions, or an empty list.
  • Each part is a non-negative integer.
Hint 1

Turn each version into a list of ints.

Hint 2

Pad with zeros so '3.10' and '3.10.1' compare correctly.

Hint 3

Search for the boundary between True and False.

Common mistakes
  • Sorting version strings as text.
  • Calling supports on every version (linear search).
  • Calling supports twice on the same index in one step.
Understand the idea

Binary search works on any monotone predicate, not just sorted numbers. The trick is often to define the right order first. Versions are hierarchical (major, then minor, then patch), and comparing integer tuples respects that hierarchy. The same pattern, sometimes called bisection, finds the first bad commit in git and the largest batch size that fits in memory.

Topics
MLOps
Similar questions
  • Catch train-serving skew in feature pipelinesMedium
  • Drive a staged canary rollout from per-window error ratesMedium
  • Pick a champion model with guardrail metricsMedium
  • Measure feature drift with smoothed KL divergence on quantile binsMedium
All MLOps problems
Report
780 / 903
Python 3solution.pyPython idle
1
2
3
4
def newest_supported(versions, supports):
# return the newest supported version string or None
pass
​
_probe(V1, '3.10')

This case uses generated data, so it runs as written. Press + to add your own case.

Run checks these cases in your browser, no sign-in needed. Submit checks the full hidden test set with Pro.

Ctrl/Cmd + Enter to run
© BlogLLM, Bengaluru, IndiaAboutTermsPrivacyRefundsDMCAContactRSS