Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/LeetCode/Weekly Contest 407/3229. Minimum Operations to Make Array Equal to Target
Prev
LeetCodeLeetCode
Hard
Weekly Contest 407

3229. Minimum Operations to Make Array Equal to Target

ArrayGreedy
Loading...
Solve on LeetCode

Problem Statement

Official algorithmic problem description and constraints.

Open on LeetCode

You are given two positive integer arrays nums and target, of the same length.

In a single operation, you can select any 

subarray

ofnumsand increment or decrement each element within that subarray by 1.Return the minimum number of operations required to make nums equal to the array target.

 

Example 1:

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

Output: 2

Explanation:

We will perform the following operations to make nums equal to target:

- Increment nums[0..3] by 1, nums = [4,6,2,3].

- Increment nums[3..3] by 1, nums = [4,6,2,4].

Example 2:

Input: nums = [1,3,2], target = [2,1,4]

Output: 5

Explanation:

We will perform the following operations to make nums equal to target:

- Increment nums[0..0] by 1, nums = [2,3,2].

- Decrement nums[1..1] by 1, nums = [2,2,2].

- Decrement nums[1..1] by 1, nums = [2,1,2].

- Increment nums[2..2] by 1, nums = [2,1,3].

- Increment nums[2..2] by 1, nums = [2,1,4].

 

Constraints:

  • 1 <= nums.length == target.length <= 105
  • 1 <= nums[i], target[i] <= 108


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Weekly Contest 407
Previous Problem