Tap here to switch tabs
Problem
Submissions

Problem: Sum of Absolute Differences in a Sorted Array

Try to solve the Sum of Absolute Differences in a Sorted Array problem.

Statement

Given an integer array nums sorted in nondecreasing order.

Build and return an integer array result of the same length, where result[i] is equal to the sum of the absolute differences between nums[i] and every element in nums.

In other words, result[i] is equal to ∑∣\sum |nums[i] −- nums[j]∣| for all 0≤0 \leq j << nums.length.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤\leq nums[i + 1] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Absolute Differences in a Sorted Array

Try to solve the Sum of Absolute Differences in a Sorted Array problem.

Statement

Given an integer array nums sorted in nondecreasing order.

Build and return an integer array result of the same length, where result[i] is equal to the sum of the absolute differences between nums[i] and every element in nums.

In other words, result[i] is equal to ∑∣\sum |nums[i] −- nums[j]∣| for all 0≤0 \leq j << nums.length.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤\leq nums[i + 1] ≤104\leq 10^4