Minimize Branch Merge Conflicts

Asked at Amazon

Reported by the problem's creator, not verified

Import another question

Several feature branches are merged into main, one whole branch after another. A branch is a list of commits, and a commit is the list of file paths it modifies. Paths are strings and may repeat inside a commit or across commits.

A commit conflicts when it modifies at least one path that some branch merged before its own branch also modifies. A commit never conflicts with a commit of its own branch. A commit counts once no matter how many of its paths clash.

Examples

  1. Example 1

    Input: branches = [[["api/user.py"],["api/auth.py"]],[["api/auth.py"],["web/app.js"]],[["api/user.py","web/app.js"],["docs/readme.md"]]]

    Output: 2

    Explanation: Merging branches 0, 1, 2 in that order costs 2: branch 1's first commit clashes on api/auth.py, and branch 2's first commit clashes once via api/user.py and web/app.js. Every order that merges branch 2 before branch 1 costs 3, so no order does better.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.