如何分開練習無 AI 編碼與 AI 輔助編碼
Practice unaided and AI-assisted coding as two different skills
文章建議準備 OpenAI 編碼面試時,將無 AI 編碼與 AI 輔助編碼視為兩種不同技能分開練習。作者以 Python 租約有效期函式作練習,要求按合約處理到期邊界、缺失或非整數的 granted_at,以及避免修改輸入資料。無 AI 練習時先自行寫測試和修正;使用 AI 時則審查補丁,特別檢查到期比較、複製行為和 bool 被視為 int 的陷阱。
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.
來源:DEV Community · dev.to