FastPrepMinimum Moves to Match Arrays
Problems/Minimum Moves to Match Arrays

Minimum Moves to Match Arrays

IBM logoIBM● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: 2026-07-17 — Example 2 was corrected to use [2468], matching the source image, rather than [1248].

There are two arrays of integers, arr1 and arr2. One move is defined as an increment or decrement of one element in an array. Determine the minimum number of moves to match arr1 with arr2. No reordering of the digits is allowed.

Complete the function minimumMoves in the editor below.

minimumMoves has the following parameter(s):

  1. int arr1[n]: array to modify
  2. int arr2[n]: array to match

int: the minimum number of moves to match arr1 with arr2

Function

minimumMoves(arr1: int[], arr2: int[]) → int

Examples

Example 1

arr1 = [1234, 4321]arr2 = [2345, 3214]return = 10

Match 1234 with 2345. Each digit changes by 1, requiring 4 moves. Match 4321 with 3214. The digit differences are 1, 1, 1, and 3, requiring 6 moves. The total is 4 + 6 = 10.

Example 2

arr1 = [2468]arr2 = [8642]return = 16

Compare the digits of 2468 and 8642 in their fixed positions.

  • |2 - 8| = 6
  • |4 - 6| = 2
  • |6 - 4| = 2
  • |8 - 2| = 6

The minimum number of moves is 6 + 2 + 2 + 6 = 16.

Constraints

  • 1 ≤ n ≤ 105
  • 1 ≤ arr1[i], arr2[i] ≤ 109
  • The lengths of arr1 and arr2 are equal, |arr1| = |arr2|.
  • The elements arr1[i] and arr2[i] have an equal number of digits.

More IBM interview questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
  • Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
  • Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
  • Maximum Student-Teacher DistanceChubb · OAChubb interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int minimumMoves(int[] arr1, int[] arr2) {
      // write your code here
    }

}
Checking account…