Make Array Zero by Subtracting Equal Amounts (LC 2375 :)
EasyAsked in:Amazon•Stage:Online Assessment
arrayhash_table
Problem Statement
Given an integer array nums, you can repeatedly choose any positive integer x and subtract x from every non‑zero element of the array. Each operation counts as one step. Determine the minimum number of steps required to make all elements of the array equal to zero.
Input Format
The function receives a single parameter nums, an array of integers where 1 ≤ nums.length ≤ 10^5 and each element satisfies 0 ≤ nums[i] ≤ 10^9.
Output Format
Return an integer representing the minimum number of operations needed to turn the entire array into zeros.
Constraints
- 1 <= n <= 10^5
- 0 <= nums[i] <= 10^9
- All operations must use a positive integer x