Practice Minimum Elements to Add to Form a Given Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit. Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit. Note that abs(x) equals x if x >= 0, and -x otherwise.
Source: Minimum Elements to Add to Form a Given Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,-1,1], limit = 3, goal = -4
2
# Example 2
nums = [1,-10,9,1], limit = 100, goal = 0
1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Elements to Add to Form a Given Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.