577. Minimum Operations to Make Numbers Non-positive
You are given a 0-indexed array nums of positive integers and two integers, x and y (with 1 ≤ y < x).
In one operation, you choose an index i and do the following:
- Subtract x from nums[i].
- Subtract y from every other element in the array.
Determine the minimum number of operations needed to make every element in nums less than or equal to zero.
Example 1:
Input : nums = [5, 3, 8], x = 5, y = 2.
Output : 3.
Explanation :
- Op 1: Target index 2 → Array becomes [3, 1, 3].
- Op 2: Target index 0 → Array becomes [-2, -1, 1].
- Op 3: Target index 2 → Final array: [-4, -3, -4].
Example 2:
Input : nums = [2, 4, 3], x = 3, y = 1.
Output : 2.
Explanation :
- Op 1: Target index 1 → Array becomes [1, 1, 2].
- Op 2: Target index 2 → Final array: [0, 0, -1].
Now Your Turn!
Pick the correct output for the given inputInput : nums = [9, 7, 12, 10]. x = 6, y = 5
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ nums.length ≤ 10⁵
- 1 ≤ nums[i] ≤ 10⁹
- 1 ≤ y < x ≤ 10⁹