Sum of Absolute Differences in a Sorted Array

Given a sorted integer array, build and return an array where each element at index i is the summation of absolute differences between the element at index i and all other elements in the array.

Constraints

  • 2 <= nums.length <= 100000
  • 1 <= nums[i] <= nums[i + 1] <= 10000
Saving… · 3 lines
class Solution:
def sumOfAbsoluteDifferencesInSortedArray(self, nums: List[int]) -> List[int]:

Console

Click Run to execute sample tests.