Panda Guru LogoPanda
Guru

Minimum Moves to Match Digits

Round 1

Questions: You are given two integer arrays arr1 and arr2, both of length n. Your task is to determine the minimum number of moves required to make each integer in arr1 match the corresponding integer in arr2.

A move is defined as incrementing or decrementing a single digit of a number by 1. You cannot change the position of digits or swap digits between numbers.

It is guaranteed that every number in arr1 and arr2 has the same number of digits.

Return the total number of moves required.

Example 1: Input:

arr1 = [321, 567]
arr2 = [123, 766]

Output: 9

Explanation: We compare digits one by one:

321 vs 123:
3 → 1 (2 moves)
2 → 2 (0 moves)
1 → 3 (2 moves)

567 vs 766:
5 → 7 (2 moves)
6 → 6 (0 moves)
7 → 6 (1 move)
Total moves required = 9.

Example 2:

Input: arr1 = [45, 89]
arr2 = [12, 67]

Output: 8

Explanation: 45 vs 12:
4 → 1 (3 moves)
5 → 2 (3 moves)

89 vs 67:
8 → 6 (2 moves)
9 → 7 (2 moves)
Total moves required = 8.

Constraints: 1 <= n <= 10^5 (length of arr1 and arr2)
0 <= arr1[i], arr2[i] <= 10^9 (values in arr1 and arr2 are non-negative integers)
The number of digits in arr1[i] and arr2[i] is the same for every i.

Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.