FastPrepMinimum Adjacent Transpositions
Problems/Minimum Adjacent Transpositions

Minimum Adjacent Transpositions

Epic logoEpic● MediumFULLTIMENEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the goal, the rule that only neighbors can be swapped, the condition for when it is possible, an example, and the shape of the function. We added a fixed set of allowed characters and a 64-bit result. Our version is about 99% the same as the reported exercise.

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) → long

Examples

Example 1

source = "GUM"target = "MUG"return = 3

Moving M to the front takes two swaps, then moving U ahead of G takes one more.

Example 2

source = "aabb"target = "bbaa"return = 4

Each 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

  • Character Frequencies in First-Appearance OrderOA · Seen Sep 2026
  • First Completed Mingo LineOA · Seen Sep 2026
  • Telephone Keypad String EncodingOA · Seen Sep 2026
  • Palindrome WordOA · Seen Sep 2024

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
All Epic interview questionsSee Epic hiring insights
Saved
class Solution {
    public long minimumAdjacentSwaps(String source, String target) {
        // Write your code here.
    }
}
Checking account…