#3762
Minimum Operations to Equalize Subarrays
grandmaster · 2215 · lc hard +32 · 19.5% accepted · 49 likes · top 1%
Description
Given an integer array nums, an integer k, and a 2D array queries where each entry is [li, ri], find for every query the minimum number of increment/decrement-by-k operations needed to make all elements in the subarray nums[li..ri] equal (or -1 if impossible), and return the results as an array ans.
Code
1
2
3