3698. Minimum Operations to Make Subarray Elements Equal

Medium
Array
Hash Table
Math
Sliding Window
Heap (Priority Queue)

Description

Hints

Hint 1
It can be proven that for each subarray of size <code>k</code>, 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.

Statistics

Acceptance
46.8%
Submissions
1,408
Accepted
659