Resolve CODEOWNERS Owners for a Changed File Path
Last updated: November 29, 2026
Quick Overview
Given an ordered list of CODEOWNERS rules (glob pattern, owners) and a file path, return the owners for that path, where the last matching rule wins. Support `*` and `?` within a segment, `**` across segments, a leading `/` anchoring to the repo root, a trailing `/` meaning a directory, and bare names matching at any depth.
GitHub
November 29, 20260
0
0 solved
Given an ordered list of CODEOWNERS rules (glob pattern, owners) and a file path, return the owners for that path, where the last matching rule wins. Support `*` and `?` within a segment, `**` across segments, a leading `/` anchoring to the repo root, a trailing `/` meaning a directory, and bare names matching at any depth.
When a pull request opens, GitHub evaluates CODEOWNERS for every changed file to request reviewers, so matching has to be correct and fast. The interviewer probes whether you can turn gitignore-style rules into a precise spec, implement glob matching with dynamic programming instead of fragile regex hacks, and apply the last-match-wins rule.
What the Interviewer Expects
- Pins down semantics before coding: anchoring, directory patterns, bare names
- Splits pattern and path into segments and matches segment by segment
- Uses memoized DP for `**` across segments and `*` within a segment
- Iterates rules from the bottom so the last match wins
- Analyzes worst-case cost and proposes precompilation or a trie for many files
- Tests tricky paths such as a nested directory with the same name
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- A PR touches 20,000 files and CODEOWNERS has 2,000 rules. How do you make this fast?
- How would you support negation, or an entry with no owners that un-assigns a path?
- How would you lint a CODEOWNERS file to flag rules that can never match because a later rule shadows them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Semantics (gitignore-like, confirm with the interviewer):
/docs/: anchored, matches everything under rootdocs.*.js: no slash, so it matches at any depth.src/**/test_*.py: contains ...
High-Level Design
Compile each pattern into a list of segments: prepend ** for bare names, append ** so a pattern also covers files beneath a matched directory. Matching is then a two-level DP: an outer one over se...