As reported: Nutanix MTS 2 (2026), round 1 DSA: transform
aintobwith the minimum number of operations; the round got stuck on an edge case and ran out of time despite hints. A second question in the same round was Book Allocation.
You are given an integer array a of length n and an integer array b of length n + 1. In one operation you may:
- increase any element of
aby 1; - decrease any element of
aby 1; - copy any element of
aand append the copy to the end ofa.
Return the minimum number of operations to make a equal to b (a[i] == b[i] for every index).
Example 1
a = [1], b = [2,3] -> 3
Increase to [2], copy → [2,2], increase the copy → [2,3].
Example 2
a = [3,3,3], b = [3,3,3,3] -> 1
Example 3
a = [5,2,1,4,6], b = [4,1,5,4,6,7] -> 8
Constraints: 1 ≤ n ≤ 10^5; -10^9 ≤ a[i], b[i] ≤ 10^9.
Code runner format: one JSON value per line: a, then b. Implement minOperations(a, b); the harness prints the count (it can exceed 32 bits).