If you are preparing for an OpenAI coding interview, start from the company's own interview guide, not from a guess about whether AI tools are allowed. The guide says assessment formats vary by team, and that "Expectations for AI and other tools vary by interview: some formats intentionally allow them, while others are designed to assess your independent problem-solving without AI tools." Allowed tools are explained in your preparation materials; if you are unsure, ask your recruiter before the interview. Practice both modes; they are different skills.
Unaided practice is for rounds that test whether you can read a contract, form a plan, change the code, and explain the result. OpenAI's guide says engineering interviews generally look for well-designed solutions, high-quality code, optimal performance, and good test coverage, plus communication and reasoning. Success means you can defend the fix yourself.
AI-assisted practice is for rounds that allow tools. Success means you can specify the contract, review a patch, reject a plausible wrong fix, and still explain every line you keep. Emitting a passing function is not the skill. Reviewing it is.
A short debugging exercise
This exercise was created for practice. It is not an OpenAI interview question.
Contract. leases maps a resource id to a record that may contain granted_at and other fields, such as holder. Records contain only immutable scalar values. Return a new dict of leases still active at time now.
- A lease is active iff
granted_atis anint(not abool) andnow < granted_at + ttl_seconds. Expiry is exclusive: the lease is gone at the exact expiry instant. - If
ttl_seconds <= 0, return{}. - Drop a missing or non-integer
granted_at. - Do not mutate
leasesor its records. Return a new outer dict and a shallow copy of each retained record.
Starter code (intentionally buggy):
def retain_active_leases(leases, now, ttl_seconds):
if ttl_seconds < 0:
return {}
for resource_id, lease in list(leases.items()):
granted_at = lease.get("granted_at", now)
if now > granted_at + ttl_seconds:
del leases[resource_id]
return leases
Check these cases before changing a line: {} returns {}. A ttl of 0 or less returns {} and leaves the input unchanged. If granted_at = 10 and ttl_seconds = 5, the lease is active at now = 14 and expired at now = 15. Drop a missing granted_at, the string "10", or True. In Python, bool is a subclass of int, so isinstance(True, int) is not enough. Assigning a field in a returned record must not change the input.
One correct version:
def retain_active_leases(leases, now, ttl_seconds):
if ttl_seconds <= 0:
return {}
active = {}
for resource_id, lease in leases.items():
granted_at = lease.get("granted_at")
if type(granted_at) is not int:
continue
if now < granted_at + ttl_seconds:
active[resource_id] = dict(lease)
return active
How to use it twice
Unaided, about 25 minutes. Write tests from the contract and cases above, then fix the starter. After each change, say why the old line was wrong: ttl_seconds == 0 was missed, the expiry comparison was wrong, a missing granted_at was treated as now, and the function mutated and returned the input. Do not ask a model until you have your own passing version.
AI-assisted, same exercise, later. Paste the contract and the buggy starter. Ask for a fix and tests, then review exclusive expiry, ttl_seconds == 0, mutation, copies, and the bool trap. If the model "fixes" expiry with <= or returns the same objects it was given, reject the patch even if a happy-path test passes. Drop any explanation that does not match the code.
One session builds fluency without tools. The other builds the judgment to use tools without handing over the contract.
I built Frontier Rehearsal, an independent site with browser-based Python labs. It is not affiliated with OpenAI, and I do not claim that any exercise is official or was asked in a real interview. For a real loop, the recruiter's instructions take precedence.
This draft was generated with AI assistance. The practice exercise was tested locally.
Top comments (0)