Minimum Operations to Make Array Elements Zero
You are given a 2D array queries, where queries[i] is of the form [l, r]. Each queries[i] defines an array of integers nums consisting of elements ranging from l to r, both inclusive.
In one operation, you can:
- Select two integers
aandbfrom the array. - Replace them with
floor(a / 4)andfloor(b / 4).
Your task is to determine the minimum number of operations required to reduce all elements of the array to zero for each query. Return the sum of the results for all queries.
Example 1
Input
queries = [[1,2],[2,4]]Output
3For the first query the minimum is 1 operation, and for the second query the minimum is 2 operations, so the sum is 3.
Example 2
Input
queries = [[2,6]]Output
4For the only query, the minimum number of operations required to reduce all elements from 2 to 6 to zero is 4.
Constraints
- 1 <= queries.length <= 10^5
- queries[i].length == 2
- queries[i] == [l, r]
- 1 <= l < r <= 10^9