Tap here to switch tabs
Problem
Submissions

Problem: Make Array Empty

Make Array Empty asks you to repeatedly process an array of distinct values: remove its front element when it is currently smallest, or move it to the back, and return the operations needed.

Statement

You are given an integer array nums containing distinct values.

In each operation, you can perform one of the following actions:

  • If the first element of the array is the smallest element currently present in nums, remove it.

  • Otherwise, move the first element from the front to the end of nums.

Return the total number of operations required to make nums empty.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • All values in nums are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Make Array Empty

Make Array Empty asks you to repeatedly process an array of distinct values: remove its front element when it is currently smallest, or move it to the back, and return the operations needed.

Statement

You are given an integer array nums containing distinct values.

In each operation, you can perform one of the following actions:

  • If the first element of the array is the smallest element currently present in nums, remove it.

  • Otherwise, move the first element from the front to the end of nums.

Return the total number of operations required to make nums empty.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • All values in nums are distinct.