Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Elements Zero

Minimum Operations to Make Array Elements Zero asks for the total minimum operations across ranges of consecutive integers. Each operation divides two positive values by four, rounding down.

Statement

You are given a 22D integer array queries, where queries[i] = [l, r].

For each query, an array nums is formed containing consecutive integers from l to r inclusive, such that nums =[l,l+1,…,r]= [l, l + 1, \dots, r].

In a single operation, you can select two distinct indices i and j where nums[i] > 0 and nums[j] > 0, and simultaneously replace nums[i] with ⌊nums[i]/4⌋\lfloor {nums}[i] / 4 \rfloor and nums[j] with ⌊nums[j]/4⌋\lfloor {nums}[j] / 4 \rfloor.

Return the sum of the minimum number of operations required to reduce all elements of nums to 00 for all queries.

Constraints:

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • queries[i] =[l,r]= [l, r]

  • 1≤l<r≤1091 \leq l < r \leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Elements Zero

Minimum Operations to Make Array Elements Zero asks for the total minimum operations across ranges of consecutive integers. Each operation divides two positive values by four, rounding down.

Statement

You are given a 22D integer array queries, where queries[i] = [l, r].

For each query, an array nums is formed containing consecutive integers from l to r inclusive, such that nums =[l,l+1,…,r]= [l, l + 1, \dots, r].

In a single operation, you can select two distinct indices i and j where nums[i] > 0 and nums[j] > 0, and simultaneously replace nums[i] with ⌊nums[i]/4⌋\lfloor {nums}[i] / 4 \rfloor and nums[j] with ⌊nums[j]/4⌋\lfloor {nums}[j] / 4 \rfloor.

Return the sum of the minimum number of operations required to reduce all elements of nums to 00 for all queries.

Constraints:

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • queries[i] =[l,r]= [l, r]

  • 1≤l<r≤1091 \leq l < r \leq 10^9