Assign code reviewers from the files changed between branches
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Apr 2026. It tests git, api integration and parsing.
When a pull request opens, pick a reviewer automatically: compare two branches, find the files that changed, look up who owns each file in a CSV, and return the owner of the most changed files. In a real tool a Git library (for example JGit in Java) would produce the diff; here each branch is given as its list of files with a version.
Interface
Unless you agree on a different interface with the interviewer, assume:
pick_reviewer(base_files: list[tuple[str, str]], target_files: list[tuple[str, str]], owners_csv: str) -> str- Each branch is a list of
(file_path, version)pairs. A file has changed if it exists in only one branch, or in both with different versions. Versions are opaque strings compared for equality. -
owners_csvhas onefile_path,ownerper non-empty line. - Ignore changed files with no owner. Return
""if no changed file has one. On a tie, return the alphabetically smallest owner so the result is deterministic.
Example
base = [("api/charge.py", "1"), ("api/refund.py", "1"), ("lib/json.py", "1")]
target = [("api/charge.py", "2"), ("api/refund.py", "1"), ("lib/json.py", "3"),
("api/payout.py", "1")]
owners = "api/charge.py,dana\napi/refund.py,eli\nlib/json.py,eli\napi/payout.py,dana"
pick_reviewer(base, target, owners) -> "dana"
# changed: charge.py (dana), json.py (eli), payout.py (dana, added); refund.py is unchanged
Constraints
- Up to 10^5 files per branch and 10^5 CSV rows.
- Each path appears at most once per branch.
Clarifying questions
- Do deleted files count as changed, and who reviews them?
- Can a file have several owners, or can an owner be a directory pattern rather than an exact path?
- Should the author of the change be excluded from the candidates?
- What happens on a tie, and should we return one reviewer or a ranked list?
What a strong answer covers
- Dicts for both branches, then one pass over the union of paths: O(n + m) time.
- CSV parsing that tolerates blank lines, stray whitespace and a header row, and says what it does with malformed lines.
- Counting with a map and a deterministic tie-break.
- With the real Git library: diffing the two branch tips (or the merge base), and handling renames.
- Tests for added, deleted and modified files, unowned files and ties.
Follow-ups
- Owners are directory prefixes (
src/payments/): match each file to its most specific owner. - Return the smallest set of reviewers that covers every owned changed file.
- Spread review load so the same person is not picked every time.
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Apr 202660 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
What it tests
git · api integration · parsing
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.
