FastPrepMinimum Merge Conflicts
Problems/Minimum Merge Conflicts

Minimum Merge Conflicts

Amazon logoAmazon● HardINTERNFULLTIMENEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on July 28, 2026, September 13, 2026, September 17, 2026, and October 5, 2026! (˶ᵔ ᵕ ᵔ˶) 💜

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.

More Amazon Online Assessment questions

  • Lexicographically Largest IdentifierOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fill One Exact-Length Binary WindowOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026

Similar questions at other companies

  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
  • Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
  • Distinct MovesMeesho · OA
  • Compressed Representation SizeMicrosoft · OAMicrosoft interview questions
  • Find Minimum OperationsIBM · OAIBM interview questions
  • String Challenge (Generic)TikTok · OATikTok interview questions
  • Maximize the Lottery IDCitadel · OACitadel interview questions
  • Sum of All ValuesFlexport · OAFlexport interview questions
  • Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 of 5)
  • Amazon Experienced Hire OA and Interviews: 21 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int getMinimumConflicts(String primary, String secondary) {
        // write your code here
    }

}
Checking account…