def minConflicts(primary: str, secondary: str) -> int:
The round: the coding half of Amazon's online assessment, next to an AI-assisted debugging task in a code repository. Three candidates reported it between April and September 2026. Two of them describe the rules in full; nobody posted constraints or a worked example, so the examples here are ours, apart from the reported "zab" count. The function name is ours.
Problem
Two branches have commit histories primary and secondary, each a string of lowercase letters. Each letter is a commit's priority: a smaller letter is a higher priority (a highest, z lowest). Merge the two histories into one string that keeps each branch's own order. A conflict is any pair of commits in the merged string where a lower-priority commit comes before a higher-priority one; for example, "zab" has 2 conflicts (z before a, z before b). Return the minimum number of conflicts over all merges.
def minConflicts(primary: str, secondary: str) -> int: ...
Examples (ours)
primary = "za", secondary = "b" merges: "zab" 2, "zba" 3, "bza" 2 -> 2
primary = "acd", secondary = "b" "abcd" has none -> 0
primary = "b", secondary = "caa" "caab" has 3 (c>a, c>a, c>b) -> 3
Pairs inside one branch count too: they are in the merged string whatever you do, so they add the same amount to every merge. Two commits with the same letter have the same priority and never conflict.
One candidate rates it a medium-to-hard string DP. One candidate, contacted by a recruiter, used backtracking to enumerate the merges, realised afterwards it needed DP, and got a rejection the next day. Each of the three reports pairs it with an AI-assisted debugging task (a return-risk scoring system, and movie applications in Spring Boot).
Also reported as Merging Branches · Merge Two Strings with Minimum Conflicts
The round: the coding half of Amazon's online assessment, next to an AI-assisted debugging task in a code repository. Three candidates reported it between April and September 2026. Two of them describe the rules in full; nobody posted constraints or a worked example, so the examples here are ours, apart from the reported "zab" count. The function name is ours.
Problem
Two branches have commit histories primary and secondary, each a string of lowercase letters. Each letter is a commit's priority: a smaller letter is a higher priority (a highest, z lowest). Merge the two histories into one string that keeps each branch's own order. A conflict is any pair of commits in the merged string where a lower-priority commit comes before a higher-priority one; for example, "zab" has 2 conflicts (z before a, z before b). Return the minimum number of conflicts over all merges.
def minConflicts(primary: str, secondary: str) -> int: ...
Examples (ours)
primary = "za", secondary = "b" merges: "zab" 2, "zba" 3, "bza" 2 -> 2
primary = "acd", secondary = "b" "abcd" has none -> 0
primary = "b", secondary = "caa" "caab" has 3 (c>a, c>a, c>b) -> 3
Pairs inside one branch count too: they are in the merged string whatever you do, so they add the same amount to every merge. Two commits with the same letter have the same priority and never conflict.
What candidates report: Two candidates describe the same rules: keep each branch's order, a smaller letter is a higher priority, and a conflict is a lower-priority commit before a higher-priority one; one of them gives "zab" as having 2 conflicts.; One candidate rates it a medium-to-hard string DP.; One candidate enumerated merges with backtracking and concluded afterwards that it needed DP.
Outcomes: The backtracking candidate was rejected the next day.
Our note (not from the reports): DP over the two prefixes: a commit placed last conflicts with every already-placed commit of the other branch that has lower priority. Always taking the higher-priority head first is wrong.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 57 Amazon questions, refreshed monthly from new candidate reports.