← 返回 amazon 的题目列表Minimum Conflicts in Merging Two Branches
类型:online_judge
Given two strings primary and secondary representing commit sequences of a primary and a secondary branch, merge them into a single sequence such that:
The relative order of characters within each original string is preserved (i.e., an interleaving).
Each character encodes a commit priority; a lower alphabetical order means a higher priority (e.g., a has higher priority than b).
A “conflict” is an inversion pair in the merged sequence: for indices i < j, if merged[i] has lower priority (lexicographically larger) than merged[j] (lexicographically smaller), this contributes 1 conflict.
Compute the minimum possible number of conflicts over all valid merges.
Function: getMinimumConflicts(primary, secondary) -> int
Constraints:
1 ≤ |primary|, |secondary| ≤ 1000
Both strings contain lowercase English letters only.
Example (from screenshot):
primary = "dae", secondary = "add" -> output 1.
Return the minimum number of conflicts.
Example
Input
dae
add
Output
1