ABB Off Campus hiring OA 2022 | Minimum Operations to Reduce X to Zero | Sliding Window

Question · Posted Jun 2026

Problem Statement You are given an integer array nums and an integer x. In one operation, you can remove either the leftmost element or the rightmost element from the array and subtract its value from x. Return the minimum number of operations required to reduce x exactly to 0. If it is not possible, return -1. Example 1 Input: nums = [1,1,4,2,3] x = 5 Output: 2 Explanation: Remove 3 and 2 from the right side. x = 5 - ...

The full answer & interview discussion are available to premium members.

Log in Create a free account