Search
⌘K
Get Premium
Leetcode 1658. Minimum Operations to Reduce X to Zero
Remove elements from either end to make the sum of removed elements equal x; equivalently, find the longest contiguous subarray whose sum equals total(nums) - x (so you minimize removed count) and return n - length, or -1 if no such subarray exists — solvable in O(n) with a sliding-window/hashmap approach.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.