AmazonOA #255
Make Array Zero by Subtracting Equal Amounts (LC 2375 :)
Estimated EasyJudge-ready
Topics (AI-labelled)Hashing
In a non-negative array, each step chooses a positive integer x no greater than the current smallest non-zero element and subtracts x from every positive element; elements equal to 0 stay 0. Find the minimum number of steps to make every element zero.
Input
The first line contains n; the second line contains the array. 1≤n≤100, 0≤element≤100.
Output
Output a single integer, the answer.
Example 1
Input:
5
1 5 0 3 5
Output:
3
Example 2
Input:
1
0
Output:
0
Example 3
Input:
3
2 2 2
Output:
1
Example notes
The answers are 3, 0 and 1. Repeated equal positive values reach zero in the same operation.
Editorial
Loading solution…