Search
⌘K

Leetcode 2615. Sum of Distances

For each index, compute the sum of absolute differences between its index and all other indices with the same value; if no duplicates exist, the sum is 0. The challenge is to do this efficiently for up to 1e5 elements by grouping equal values and using prefix/suffix sums over each group's index list to compute each sum in constant time per index.


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.