leetle

Daily challenge for 2026-04-12

467. Sum of Absolute Differences

Given an array of integers nums, calculate the sum of the absolute differences between every pair of elements in the array. Specifically, for every pair of indices $(i, j)$ where $0 \le i < j < \text{length of } nums$, calculate $|nums[i] - nums[j]|$, and return the total sum of all these differences.

Input: nums = [1, 3, 2]
Output: 4
Explanation: The pairs are (1, 3), (1, 2), and (3, 2). $|1 - 3| = 2$, $|1 - 2| = 1$, $|3 - 2| = 1$. Total sum = $2 + 1 + 1 = 4$.

Run this challenge interactively in Python or JavaScript when the app loads.