Free written solution

Make Array Zero by Subtracting Equal Amounts (LeetCode 2357): Solution and Explanation

Each operation subtracts the same positive x (no larger than the smallest non-zero element) from every positive element. Return the fewest operations that turn nums into all zeros.

Read the intuition, approach, code and complexity →