Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Form Subsequence With Target Sum

med
30 min
Try to solve the Minimum Operations to Form Subsequence With Target Sum problem.

Statement

You are given an integer array nums consisting of powers of 22, and an integer target.

In a single operation, you can select any element nums[i] such that nums[i] >1> 1, remove it from nums, and add two occurrences of nums[i] /2/ 2 to nums.

Return the minimum number of operations required to make nums contain a subsequence whose sum is equal to target. If no such subsequence can be formed, return −1-1.

Note: A subsequence is an array obtained by deleting zero or more elements from another array without altering the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤230\leq 2^{30}

  • nums consists only of powers of 22 with non negative exponents.

  • 1≤1 \leq target <231< 2^{31}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Form Subsequence With Target Sum

med
30 min
Try to solve the Minimum Operations to Form Subsequence With Target Sum problem.

Statement

You are given an integer array nums consisting of powers of 22, and an integer target.

In a single operation, you can select any element nums[i] such that nums[i] >1> 1, remove it from nums, and add two occurrences of nums[i] /2/ 2 to nums.

Return the minimum number of operations required to make nums contain a subsequence whose sum is equal to target. If no such subsequence can be formed, return −1-1.

Note: A subsequence is an array obtained by deleting zero or more elements from another array without altering the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤230\leq 2^{30}

  • nums consists only of powers of 22 with non negative exponents.

  • 1≤1 \leq target <231< 2^{31}