#2659
Make Array Empty
international master · 2060 · lc hard +32 · verified · 26.7% accepted · 571 likes · top 5%
Description
You are given an integer array nums of distinct values. Repeatedly: if the front element is the current minimum, remove it; otherwise move it to the back. Return the total number of operations needed to empty nums.
Example 1:
Input: nums = [3,4,-1]
Output: 5
Example 2:
Input: nums = [1,2,4,3]
Output: 5
Example 3:
Input: nums = [1,2,3]
Output: 3
Code
1
2
3