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
Coding & Algorithms
Software Engineer
GitHub
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
string parsing
glob matching
dynamic programming
memoization
CODEOWNERS
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements

Semantics (gitignore-like, confirm with the interviewer):

  • /docs/ : anchored, matches everything under root docs.
  • *.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...


Submit Your Answer
Markdown supported