Class Solution
java.lang.Object
g2501_2600.s2598_smallest_missing_non_negative_integer_after_operations.Solution
2598 - Smallest Missing Non-negative Integer After Operations.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>value</code>.</p>
<p>In one operation, you can add or subtract <code>value</code> from any element of <code>nums</code>.</p>
<ul>
<li>For example, if <code>nums = [1,2,3]</code> and <code>value = 2</code>, you can choose to subtract <code>value</code> from <code>nums[0]</code> to make <code>nums = [-1,2,3]</code>.</li>
</ul>
<p>The MEX (minimum excluded) of an array is the smallest missing <strong>non-negative</strong> integer in it.</p>
<ul>
<li>For example, the MEX of <code>[-1,2,3]</code> is <code>0</code> while the MEX of <code>[1,0,3]</code> is <code>2</code>.</li>
</ul>
<p>Return <em>the maximum MEX of</em> <code>nums</code> <em>after applying the mentioned operation <strong>any number of times</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,-10,7,13,6,8], value = 5</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong></p>
<p>One can achieve this result by applying the following operations:</p>
<ul>
<li>
<p>Add value to nums[1] twice to make nums = [1, <strong><ins>0</ins></strong> ,7,13,6,8]</p>
</li>
<li>
<p>Subtract value from nums[2] once to make nums = [1,0, <strong><ins>2</ins></strong> ,13,6,8]</p>
</li>
<li>
<p>Subtract value from nums[3] twice to make nums = [1,0,2, <strong><ins>3</ins></strong> ,6,8]</p>
</li>
</ul>
<p>The MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,-10,7,13,6,8], value = 7</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>One can achieve this result by applying the following operation:</p>
<ul>
<li>subtract value from nums[2] once to make nums = [1,-10,<ins> <strong>0</strong> </ins>,13,6,8]</li>
</ul>
<p>The MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length, value <= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findSmallestInteger
public int findSmallestInteger(int[] nums, int value)
-