All problems
0973EasyArrayHash TableGreedySortingHeap (Priority Queue)Simulation

Rounds Needed to Clear Every Reading

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2357Make Array Zero by Subtracting Equal Amounts

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Readings are given as nums.

One round picks a number k above zero, no larger than the smallest reading that is still above zero, and takes k off every reading that is above zero.

Return the fewest rounds that leave every reading at zero.

Examples

Example 1

Input
nums = [14, 3, 27, 3, 9, 0]
Output
4

The distinct readings above zero are 14, 3, 27 and 9, so four rounds are needed: taking off 3, then 6, then 5, then 13.

Example 2

Input
nums = [5, 5, 5, 5]
Output
1

All four readings are the same, so one round of five clears them together.

Example 3

Input
nums = [0, 0, 0]
Output
0

Everything already reads zero, so no rounds are needed.

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 100

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def minimum_operations(nums: list[int]) -> int:
Java
public int minimumOperations(int[] nums)
September 7
Apply