Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write a NodeJS Addon

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Write a NodeJS Addon. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement the matching algorithm behind a Node.js native addon used by GitHub to resolve CODEOWNERS-style ownership for repository paths. For every path, return the owner from the highest-precedence matching pattern, or None when no pattern matches.

Formal Specification

Implement resolve_codeowners(patterns, paths). patterns is a list of objects with pattern and owner string fields. paths is a list of repository-relative POSIX paths. Return a list containing one owner string or None for each path.

Patterns are anchored at the repository root and are split on /. A segment containing * matches any sequence of characters except /; ? matches exactly one non-slash character. A segment equal to ** matches zero or more complete path segments. Patterns do not contain escaped characters.

A matching pattern wins by, in order: the greatest number of literal characters, the fewest wildcard tokens, then the greatest original pattern index. This makes ties follow the later CODEOWNERS rule.

Constraints

  • 1 <= len(patterns), len(paths) <= 10^4
  • Each pattern and path has at most 100 segments
  • Each segment has at most 100 characters
  • Pattern and path characters are printable ASCII except /
  • Every pattern has a non-empty owner

Function Signature

def resolve_codeowners(patterns, paths):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output