FastPrepMinimum Digit Swaps for the Smallest Difference
Problems/Minimum Digit Swaps for the Smallest Difference

Minimum Digit Swaps for the Smallest Difference

LSEG logoLSEG● MediumFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The corresponding-position swaps and difference-first, swap-count-second objective match at about 90%. Length bounds, leading-zero handling and the count-only interface are exercise conventions.

Two equal-length digit strings a and b represent nonnegative decimal integers. In one move, choose an index i and swap a[i] with b[i]. All other positions stay in place.

First minimize the absolute numeric difference between the two resulting integers. Among all outcomes attaining that minimum difference, return the minimum number of moves. Return the move count, not the difference or the resulting strings.

Leading zeros do not change an integer's value. Swapping equal digits is allowed but cannot help minimize the move count.

Function

minimumDigitSwaps(a: String, b: String) → int

Examples

Example 1

a = "111"b = "222"return = 1

Swap the first digits to obtain 211 and 122, with difference 89. Keeping the first digits and swapping both later positions gives the same difference using two moves.

Example 2

a = "29162"b = "10524"return = 2

Swapping indices 1 and 3 produces 20122 and 19564, with difference 558. The opposite orientation needs three moves for the same minimum difference.

Example 3

a = "0001"b = "0001"return = 0

The integers already agree, so zero moves attains difference zero.

Constraints

  • 1 <= a.length <= 100000.
  • 1 <= b.length <= 100000.
  • a and b have the same length.
  • a and b contain only decimal digits; leading zeros are allowed.

More LSEG Online Assessment questions

  • Count Times Using at Most Two DigitsOA · Seen Jul 2025
  • Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
  • Maximum Word Count in a SentenceOA · Seen Jul 2025
  • Smallest String After at Most One DeletionOA · Seen Jul 2025
  • Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
  • Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
  • Transform a String with at Most One OperationOA · Seen Feb 2025
  • Price Equity Options and ForwardsOA · Seen Dec 2024
  • Maximum Sum of Non-Adjacent ElementsOA · Seen Sep 2024
  • Return the Sentence with the Most WordsOA · Seen Sep 2024

Similar questions at other companies

  • Return Exact Cash Register ChangeBank of America · OA
  • Maximum Binary Circuit Segregation CostAdobe · OAAdobe interview questions
  • Binary CircuitAkuna Capital · OAAkuna Capital interview questions
  • Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
  • Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
  • Minimize Difference Between Two NumbersMicrosoft · OAMicrosoft interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Smallest Number With a Given Digit SumAmazon · ONSITE INTERVIEW
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
All LSEG interview questionsSee LSEG hiring insights
Saved
class Solution {
    public int minimumDigitSwaps(String a, String b) {
        // write your code here
    }
}
Checking account…