Tap here to switch tabs
Problem
Submissions

Problem: Intervals Between Identical Elements

Intervals Between Identical Elements asks you to return an array where each position contains the total distance to every other position holding the same value, or zero if unique.

Statement

You are given an integer array arr of size n.

The interval between any two indices i and j is defined as ∣i−j∣|i - j|.

Return an array of size n where the element at index i is the sum of intervals between i and all other indices j such that arr[i] == arr[j] and i \neq j. If there is no other index with the same value as arr[i], the sum of intervals for index i is 00.

Constraints:

  • n == arr.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Intervals Between Identical Elements

Intervals Between Identical Elements asks you to return an array where each position contains the total distance to every other position holding the same value, or zero if unique.

Statement

You are given an integer array arr of size n.

The interval between any two indices i and j is defined as ∣i−j∣|i - j|.

Return an array of size n where the element at index i is the sum of intervals between i and all other indices j such that arr[i] == arr[j] and i \neq j. If there is no other index with the same value as arr[i], the sum of intervals for index i is 00.

Constraints:

  • n == arr.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤105\leq 10^5