Ezvor

3422. Minimum Operations to Make Subarray Elements Equal

MediumArray Preparing judge… LeetCode
ArrayHash TableMathSliding WindowHeap (Priority Queue)

Hints

Hint 1
It can be proven that for each subarray of size k, one optimal common value is the median.
Hint 2
Use 2 multisets to maintain the median dynamically.
Hint 3
Calculate the sums of the 2 multisets dynamically to accelerate the answer calculation.