Practice Minimum Operations to Form Subsequence With Target Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#2835
LeetCode ProblemMinimum Operations to Form Subsequence With Target Sum
Problem Statement
nums contains powers of 2. In one operation choose a value greater than 1, remove it, and append two copies of half that value. Return the minimum operations needed so that some subsequence sums to target, or -1 if impossible.
Source: Minimum Operations to Form Subsequence With Target Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,2,8], target = 7
Output
1
# Example 2
Input
nums = [1,32,1,2], target = 12
Output
2
# Example 3
Input
nums = [1,32,1], target = 35
Output
-1
Constraints
1 <= nums.length <= 1000
1 <= nums[i] <= 2^30
nums consists only of non-negative powers of two.
1 <= target < 2^31
Related LeetCode Problems
Practice more problems similar to Minimum Operations to Form Subsequence With Target Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.