Find a path only the new allowlist allows

Agent buildHard40 min

Your task

Your coding agent may touch only paths that match an allowlist of patterns. A teammate proposes a new list. Before it goes live, you want to see whether it lets through any path the old list refused.

Write first_new_path(old_list, new_list) that returns the shortest path the new list allows and the old list does not.

Input and output:

  • old_list, new_list: 1 to 8 patterns each. A pattern has 1 to 40 characters from a to z, /, ., * and ?.
  • Across both lists, at most 9 characters are * or ?.
  • Return a string. Return "" if there is no such path.

Rules:

  • A path is a non-empty string of characters from a to z, / and ..
  • A pattern allows a path when it matches the whole path. * matches any run of characters, including / and including no characters at all. ? matches exactly one character, including /. Every other character matches itself.
  • A list allows a path when at least one of its patterns does.
  • When several paths tie for shortest, return the first in character-code order, where . comes before / and / comes before a.

Examples

first_new_path(old_list: list[str], new_list: list[str]) -> str
Example 1
Inputfirst_new_path(["src/*", "docs/*.md"], ["src/*", "tests/*"])
Output"tests/"
Example 2
Inputfirst_new_path(["*.py", "src/*"], ["src/?.py", "src/a/*.py"])
Output""
Example 3
Inputfirst_new_path(["a*", "*a", "*?a?*"], ["*a*"])
Output""