372. Sum of Distances
MediumHash Table
You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0. Return the array arr.
Examples
Input: [1,3,1,1,2]
Output: [5,0,3,4,0]
Explanation: Public test case for Sum of Distances
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^9
Loading...
Run checks all cases above. Submit evaluates all test cases.