This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/ | |
| You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations. | |
| Return the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1 | |
| BASED ON LONGEST SUBARRAY WITH K SUM | |
| Example 1: | |
| Input: nums = [1,1,4,2,3], x = 5 | |
| Output: 2 | |
| Explanation: The optimal solution is to remove the last two elements to reduce x to zero. | |
| Example 2: |
NewerOlder