Make Array Zero by Subtracting Equal Problem
Make Array Zero by Subtracting Equal Problem — ExecCode Easy DSA Practice
Solve the Make Array Zero by Subtracting Equal problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a non-negative integer array nums. Your task is to compute the required answer and return the minimum number of operations to make every element in nums equal to 0. In one operation, you must: - Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums. - Subtract x from every positive element in nums.
Examples
Input {"nums": [1, 5, 0, 3, 5]}; Output 3. Input {"nums": [0, 0, 0, 0]}; Output 0. Input {"nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}; Output 10
Constraints
1 <= nums.length <= 100 0 <= nums[i] <= 100
Practice Make Array Zero by Subtracting Equal free on ExecCode. Browse DSA problems, topic map, and placement guides.