You are given a positive integer k. Initially, you have an array nums = [1].
You can perform any of the following operations on the array any number of times (possibly zero):
1.Return the minimum number of operations required to make the sum of elements of the final array greater than or equal to k.
Example 1:
Input: k = 11
Output: 5
Explanation:
We can do the following operations on the array nums = [1]:
1 three times. The resulting array is nums = [4].nums = [4,4,4].The sum of the final array is 4 + 4 + 4 = 12 which is greater than or equal to k = 11.
The total number of operations performed is 3 + 2 = 5.
Example 2:
Input: k = 1
Output: 0
Explanation:
The sum of the original array is already greater than or equal to 1, so no operations are needed.
Constraints:
1 <= k <= 105Solutions for this problem are being prepared.
Try solving it yourselfShortest Subarray with Sum at Least K - Leetcode 862 - Python • NeetCodeIO • 19,043 views views
Watch 9 more video solutions →Practice Apply Operations to Make Sum of Array Greater Than or Equal to k with our built-in code editor and test cases.
Practice on FleetCodePractice this problem
Open in Editor