Skip to content

Practice Make Array Empty

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Problem Statement

nums has distinct values. Repeatedly inspect its first entry: if it is the smallest remaining value, remove it; otherwise move it to the end. Each removal or move counts as one operation. Return the operations needed to empty the array.

Source: Make Array Empty on LeetCode. Use the original task for its coding environment and submissions.

Examples

# 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

Constraints

1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
All values in nums are distinct.

Related LeetCode Problems

Practice more problems similar to Make Array Empty.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.