Skip to content

Practice Minimum Operations to Make Array Equal to Target

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3229
LeetCode Problem

Minimum Operations to Make Array Equal to Target

Problem Statement

You are given two positive integer arrays nums and target, of the same length. In a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray by 1. Return the minimum number of operations required to make nums equal to the array target.

Source: Minimum Operations to Make Array Equal to Target on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,5,1,2], target = [4,6,2,4]
Output
2

# Example 2

Input
nums = [1,3,2], target = [2,1,4]
Output
5

Constraints

1 <= nums.length == target.length <= 10^5
1 <= nums[i], target[i] <= 10^8

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Make Array Equal to Target.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.