Minimum Adjacent Transpositions
Updated
Problem statement
source and target contain the same ASCII characters with the same frequencies.
In one operation, swap two adjacent characters in source. Return the minimum number of operations required to transform source into target.
Function
minimumAdjacentSwaps(source: String, target: String) → longExamples
Example 1
source = "GUM"target = "MUG"return = 3Moving M to the front takes two swaps, then moving U ahead of G takes one more.
Example 2
source = "aabb"target = "bbaa"return = 4Each of the two b characters crosses both a characters.
Constraints
1 <= source.length == target.length <= 200000- Both strings contain the same ASCII characters with the same frequencies.
More Epic Online Assessment questions
Similar questions at other companies
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Return Exact Cash Register ChangeBank of America · OABank of America interview questions