Practice Patching Array
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
Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number of patches required.
Source: Patching Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,3], n = 6
Output
1
# Example 2
Input
nums = [1,5,10], n = 20
Output
2
# Example 3
Input
nums = [1,2,2], n = 5
Output
0
Constraints
1 <= nums.length <= 1000
1 <= nums[i] <= 10^4
nums is sorted in ascending order.
1 <= n <= 2^31 - 1
Related LeetCode Problems
Practice more problems similar to Patching Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.