Reported October 2026
Amazondynamic programming

Minimum Merge Conflicts

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Most people attack Minimum Merge Conflicts by greedily taking the smaller front character, and that's the attempt that dies on the hidden tests. Amazon reported this OA in October 2026, and it's a two-string merge problem dressed up as source control. You're counting inversions in the merged string and you need the minimum over every valid interleaving. Lengths go up to 1000, so brute force is dead and an O(n*m) DP is the intended answer. If the 2D state doesn't click when the timer's running, StealthCoder sits invisibly on your screen during the live OA and hands you the solution as a safety net. Know the shape before you sit down.

The problem

Developers want to merge two source-control branches into one unified branch while preserving the relative order of commits from each branch.
Each branch is represented by a lowercase string. Each character represents a commit priority, where a lower alphabetical character has higher priority.
A conflict occurs when, in the merged branch, a lower-priority commit appears before a higher-priority commit. In other words, for positions i < j in the merged string, there is a conflict when merged[i] > merged[j].
Return the minimum possible number of conflicts over all valid merges of primary and secondary.
A valid merge must contain every character from both branches and preserve the original order within each input branch.

Function
getMinimumConflicts(primary: String, secondary: String) → int
The function getMinimumConflicts takes the following input:
string primary: the commit sequence of the primary branch
string secondary: the commit sequence of the secondary branch
Returns int: the minimum number of conflicts after a valid merge

Examples
Example 1
primary = "zc"
secondary = "d"
return = 2
Valid merges include:
zcd with 2 merge conflicts (z being lower priority is placed before higher priority commits c and d).
Similarly, zdc with 3 merge conflicts.
Similarly, dzc with 2 merge conflicts.
The minimum number of merge conflicts possible is 2.
Example 2
primary = "dae"
secondary = "add"
return = 1
adadde has 1 merge conflict.
Example 3
primary = "aaa"
secondary = "abb"
return = 0
aaaabb has no merge conflicts.
Added from a newer source found on June 24, 2026 🦒

Constraints
1 <= |primary|, |secondary| <= 1000
primary and secondary consist of lowercase English letters only.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: inversions inside each string are fixed no matter how you merge, so count them once and add them at the end. Only cross pairs depend on order. Define dp[i][j] as the minimum cross conflicts after placing i chars of primary and j of secondary. Taking primary[i] next costs the number of chars in secondary[0..j-1] strictly greater than primary[i]. Taking secondary[j] next costs the number of chars in primary[0..i-1] strictly greater than it. Precompute prefix counts per letter, 26 by (n+1), so each transition is O(1). The pitfall is greedy. Picking the smaller front char looks right and fails on ties and on cases like Example 2, where a locally cheap pick costs you later. Also don't forget the internal inversions, or Example 1 gives 1 instead of 2. If you blank on the state definition mid-assessment, StealthCoder is your hedge for the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Minimum Merge Conflicts cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Merge Conflicts FAQ

How hard is Minimum Merge Conflicts really?+

Medium to medium-hard. The code is short once you see it, but you have to spot that it's a 2D DP over how many chars you've taken from each string. If you've done interleaving-string style problems, the state will feel familiar fast.

What's the trick to solving it?+

Split the answer in two. Inversions within each string are constant, so count them directly. Then run a DP over (i, j) where each step adds the number of already-placed chars from the other string that are strictly greater than the char you place now.

Why doesn't a greedy merge work?+

Taking the smaller front character ignores what the remaining characters will cost later. Ties and large trailing characters break it. Example 2, dae and add, shows how the best order isn't just the lexicographically smallest merge. Only a DP checks every interleaving's cost.

What complexity do I need with lengths up to 1000?+

O(n*m) time, about a million states. Precompute prefix counts for each of 26 letters on both strings so each transition is O(1) instead of scanning. Memory can be a full 1001 by 1001 table, or two rolling rows if you want to trim it.

How do I prepare in 48 hours?+

Hand-trace Example 1 until you get 2, including the internal inversion. Then code the DP from scratch once, with the prefix count tables. Test the edge cases: identical strings, fully sorted strings returning 0, and one string entirely larger than the other.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it