Search
⌘K

Leetcode 2602. Minimum Operations to Make All Array Elements Equal

For each query value q, compute the minimum number of +/-1 operations to make all elements of nums equal to q, which equals the sum of absolute differences |nums[i] - q|. With n,m up to 1e5, the challenge is to answer each query efficiently by sorting nums and using prefix sums plus binary search to compute the sum of absolute differences per query.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.