Debug a project-assignment codebase
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Scale AI's coding round, last asked Apr 2026. It tests debugging, code reading and python.
You get a small codebase spread over several files that assigns projects to people (for example students to course projects, with capacities and preferences), plus a test suite in which several tests fail. Under time pressure, find your way around the code, locate the bugs, and fix them without changing the public API that the tests call.
What to do
- Run the tests and read the failures before reading all the code.
- Trace each failing test from its call through the files it touches.
- Fix each bug with the smallest change that makes the behaviour correct; don't refactor.
- Bugs in this kind of codebase are state and data-filtering mistakes, such as a counter or a list that should be reset for each iteration of a loop but is created once outside it, or a filter that compares the wrong id (a project id against a student id).
Example
def assign_all(students, projects):
assigned = [] # bug: created once
for p in projects:
for s in students:
if s.choice == p.id and len(assigned) < p.capacity:
assigned.append(s) # every project shares one list
p.members = assigned
assigned must be created inside the loop over projects; as written, the second project inherits the first one's members and its capacity check counts them.
Clarifying questions
- Which behaviour is the specification: the tests, a README, or the docstrings?
- May I change tests, or only the code?
- Is the public API fixed (names, signatures, return types)?
- Is there one known symptom, or should I find every bug?
What a strong answer covers
- A method: reproduce, read the stack trace or assertion diff, form a hypothesis, confirm it with a print or a debugger, then fix.
- Recognizing state bugs: mutable values shared across iterations, default mutable arguments, state not reset between calls.
- Recognizing filtering bugs: wrong field, wrong id, off-by-one in a capacity check,
<versus<=. - Keeping the public API stable while fixing internals, and rerunning the whole suite after each fix.
- Explaining each fix clearly, and adding a regression test where one was missing.
Follow-ups
- All tests pass now. What other bugs might still be hiding, and what test would expose them?
- Add a new rule (a student can't be assigned to two projects) without breaking existing behaviour.
- How would you make this code harder to break in the future?
Where it's asked
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
