Class Solution

java.lang.Object
g2601_2700.s2659_make_array_empty.Solution

public class Solution extends Object
2659 - Make Array Empty.<p>Hard</p> <p>You are given an integer array <code>nums</code> containing <strong>distinct</strong> numbers, and you can perform the following operations <strong>until the array is empty</strong>:</p> <ul> <li>If the first element has the <strong>smallest</strong> value, remove it</li> <li>Otherwise, put the first element at the <strong>end</strong> of the array.</li> </ul> <p>Return <em>an integer denoting the number of operations it takes to make</em> <code>nums</code> <em>empty.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,4,-1]</p> <p><strong>Output:</strong> 5</p> <pre><code> Operation Array 1 [4, -1, 3] 2 [-1, 3, 4] 3 [3, 4] 4 [4] 5 [] </code></pre> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2,4,3]</p> <p><strong>Output:</strong> 5</p> <pre><code> Operation Array 1 [2, 4, 3] 2 [4, 3] 3 [3, 4] 4 [4] 5 [] </code></pre> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,2,3]</p> <p><strong>Output:</strong> 3</p> <pre><code> Operation Array 1 [2, 3] 2 [3] 3 [] </code></pre> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>-10<sup>9 </sup><= nums[i] <= 10<sup>9</sup></code></li> <li>All values in <code>nums</code> are <strong>distinct</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countOperationsToEmptyArray

      public long countOperationsToEmptyArray(int[] nums)