Class Solution
-
- All Implemented Interfaces:
public final class Solution2598 - Smallest Missing Non-negative Integer After Operations\.
Medium
You are given a 0-indexed integer array
numsand an integervalue.In one operation, you can add or subtract
valuefrom any element ofnums.For example, if
nums = [1,2,3]andvalue = 2, you can choose to subtractvaluefromnums[0]to makenums = [-1,2,3].
The MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.
For example, the MEX of
[-1,2,3]is0while the MEX of[1,0,3]is2.
Return the maximum MEX of
numsafter applying the mentioned operation any number of times.Example 1:
Input: nums = 1,-10,7,13,6,8, value = 5
Output: 4
Explanation:
One can achieve this result by applying the following operations:
Add value to nums1 twice to make nums = 1, **<ins>0</ins>** ,7,13,6,8
Subtract value from nums2 once to make nums = 1,0, **<ins>2</ins>** ,13,6,8
Subtract value from nums3 twice to make nums = 1,0,2, **<ins>3</ins>** ,6,8
The MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.
Example 2:
Input: nums = 1,-10,7,13,6,8, value = 7
Output: 2
Explanation:
One can achieve this result by applying the following operation:
subtract value from nums2 once to make nums = 1,-10,<ins> **0** </ins>,13,6,8
The MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.
Constraints:
<code>1 <= nums.length, value <= 10<sup>5</sup></code>
<code>-10<sup>9</sup><= numsi<= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerfindSmallestInteger(IntArray nums, Integer value)-
-
Method Detail
-
findSmallestInteger
final Integer findSmallestInteger(IntArray nums, Integer value)
-
-
-
-