Leetcode 1685. Sum of Absolute Differences in a Sorted Array
Given a sorted array, compute for each index the sum of absolute differences between nums[i] and all other elements. The sorted order lets you compute each result in O(n) using prefix sums and element counts instead of an O(n^2) pairwise computation.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.