Problem Brief
Minimum Moves to Match Arrays
FULLTIMEOA
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.
Function Description
Complete the function minimumMoves in the editor below.
minimumMoves has the following parameter(s):
int arr1[n]: array to modifyint arr2[n]: array to match
Returns
int: the minimum number of moves to match arr1 with arr2
1Example 1
Input
arr1 = [1234, 4321], arr2 = [2345, 3214]
Output
10
Explanation
- Match arr1[0]=1234 with arr2[0]=2345.
- Increment 1 once to get 2 (1 move)
- Increment 2 once to get 3 (1 move)
- Increment 3 once to get 4 (1 move)
- Increment 4 once to get 5 (1 move).
- Decrement 4 once to get 3 (1 move)
- Decrement 3 once to get 2 (1 move)
- Decrement 2 once to get 1 (1 move)
- Increment 1 three times to get 4 (3 moves)
2Example 2
Input
arr1 = [1248], arr2 = [8642]
Output
16
Explanation
- Match arr1[0]=1248 with arr2[0]=8642.
- Decrement 1 seven times to get 8 (7 moves)
- Increment 2 four times to get 6 (4 moves)
- Decrement 4 two times to get 2 (2 moves)
- Increment 8 two times to get 4 (2 moves)
Constraints
Limits and guarantees your solution can rely on.