Practice problem · OpenAI · Medium

Dependency Version Support

A greenhouse-control app depends on a driver library for its sensors and valves. 2 stages in Python written by you, with an assistant that only answers. Pro.

Stage 1 of 2: The earliest supported version

Background. A greenhouse-control app depends on a driver library for its sensors and valves. When the app needs a feature from that dependency, a frost alarm for instance, the team looks for the earliest version of the library that has it. The only way to learn whether a version has a feature is to run a check on it.

Implement earliest_supported(versions, is_supported) in releases.py so that it returns the earliest version in versions that supports the feature, exactly as it is written in the list, or None when none does.

Versions

  • A version is a string major.minor.patch: exactly three parts joined by single dots, each part one or more of the characters 0 to 9. Anything else is malformed.
  • A part may start with zeros. The input never has a part longer than 25 digits, leading zeros included, so there is no length to check. Parts compare as numbers, major first, then minor, then patch: 5.009.40 is earlier than 5.10.2.
  • versions is a list of strings in any order. It may be empty, and it may hold the same string several times. Two different strings in it never name one version, so 6.05.1 and 6.5.01 are not listed together.

The check

  • is_supported(version) returns True or False. Pass it only strings from versions, exactly as written.
  • Support follows no pattern: a version can lack a feature that an earlier version has, and a still higher one can have it again.
  • While finding one answer, ask about a string at most once, however often the list repeats it.
  • If any string in the list is malformed, raise ValueError before the first call of is_supported.

Example

versions = ["3.012.0", "3.4.07", "10.0.1", "3.4.11", "3.012.0", "02.30.5"]
frost_alarm = {"3.4.07", "10.0.1"}

earliest_supported(versions, lambda v: v in frost_alarm)   # "3.4.07"
earliest_supported(versions, lambda v: False)              # None
earliest_supported(versions + ["3.4"], lambda v: True)     # ValueError, nothing asked

Notes

  • Each call of earliest_supported stands alone. The list and the check's answers may change between two calls, never during one.

Done when Submit goes green.

Constraints

  • Python 3.12 standard library only
  • Editable: releases.py
  • Read-only: all tests/test_*.py files
  • Each test file has 10 seconds to run

What comes after stage 1

The next stage opens once the tests for the one before it pass. Each raises the bar, the way an interviewer does in the room.

  1. Stage 2: Few checks. Every check is expensive now. Find the same version while asking about very few of a long history.

The files you get

  • Yours to edit: releases.py.
  • Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.

The round: no AI, an assistant that only answers

OpenAI runs this round without AI. Here the closest format is answer-only: the assistant answers your questions and reviews your code when you ask, the way an interviewer would, and never writes a line of it. The interviewer asks about your decisions as you go, and the report states the format. You can switch to the agent format when you press Begin.

Frequently asked, briefly answered

Is Dependency Version Support free?

It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.

Which company asks something like this?

OpenAI. It is modelled on OpenAI's coding round, which runs without AI. Based on candidates' reports of OpenAI interviews. Nyrion wrote this version, so the question you get may differ.

Do I bring my own AI tool?

No. The real round has no AI, so this one opens answer-only: an assistant that answers your questions and can't write code. You can switch to an agent that proposes changes when you press Begin.

What does the interviewer ask?

2 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.

Start this problem → Sign in

More like it: every practice problem, OpenAI's interviews, the AI coding interview guide.