PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Amazon

Minimize Branch Merge Conflicts

Last updated: May 2, 2026

Quick Overview

This question evaluates understanding of combinatorial optimization, set operations, and order-dependent state management, requiring reasoning about how commit file modifications accumulate across branch merges.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Minimize Branch Merge Conflicts

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You are given several feature branches that must all be merged into the main branch. Each branch contains a sequence of commits, and each commit modifies one or more file paths. Implement `minMergeConflicts(branches) -> int`. - `branches[i][j]` is the list of file paths modified by the `j`-th commit in branch `i`. - You may choose any order in which to merge the branches. - The first merged branch has zero conflicts. - When merging a branch after some other branches have already been merged, a commit in the current branch is counted as a conflicting commit if it modifies at least one file path that has already been modified by any previously merged branch. - A commit counts at most once, even if it touches multiple already-modified files. - After a branch is merged, all files modified by all of its commits are considered modified for future merges. Return the minimum possible total number of conflicting commits after merging all branches. Example: `branches = [[['a'], ['b']], [['b'], ['c']], [['a', 'c']]]` One optimal order is branch `0`, then branch `1`, then branch `2`: - Merge branch `0`: `0` conflicts. - Merge branch `1`: commit `['b']` conflicts, commit `['c']` does not, so `1` conflict. - Merge branch `2`: commit `['a', 'c']` conflicts, so `1` conflict. The minimum total conflict count is `2`. Assume the number of branches is small enough for subset dynamic programming, for example `n <= 15`.

Quick Answer: This question evaluates understanding of combinatorial optimization, set operations, and order-dependent state management, requiring reasoning about how commit file modifications accumulate across branch merges.

Related Interview Questions

  • Count Connected Components in an Undirected Graph - Amazon (medium)
  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
Amazon logo
Amazon
Jan 12, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
2
0

You are given several feature branches that must all be merged into the main branch. Each branch contains a sequence of commits, and each commit modifies one or more file paths.

Implement minMergeConflicts(branches) -> int.

  • branches[i][j] is the list of file paths modified by the j -th commit in branch i .
  • You may choose any order in which to merge the branches.
  • The first merged branch has zero conflicts.
  • When merging a branch after some other branches have already been merged, a commit in the current branch is counted as a conflicting commit if it modifies at least one file path that has already been modified by any previously merged branch.
  • A commit counts at most once, even if it touches multiple already-modified files.
  • After a branch is merged, all files modified by all of its commits are considered modified for future merges.

Return the minimum possible total number of conflicting commits after merging all branches.

Example:

branches = [[['a'], ['b']], [['b'], ['c']], [['a', 'c']]]

One optimal order is branch 0, then branch 1, then branch 2:

  • Merge branch 0 : 0 conflicts.
  • Merge branch 1 : commit ['b'] conflicts, commit ['c'] does not, so 1 conflict.
  • Merge branch 2 : commit ['a', 'c'] conflicts, so 1 conflict.

The minimum total conflict count is 2.

Assume the number of branches is small enough for subset dynamic programming, for example n <= 15.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.