FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2240,3 "name": "intervals-between-identical-elements",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/intervals-between-identical-elements/",6 "date": "2021-12-19",7 "task_description": "You are given a **0-indexed** array of `n` integers `arr`. The **interval** between two elements in `arr` is defined as the **absolute difference** between their indices. More formally, the **interval** between `arr[i]` and `arr[j]` is `|i - j|`. Return _an array_ `intervals` _of length_ `n` _where_ `intervals[i]` _is **the sum of intervals** between _`arr[i]`_ and each element in _`arr`_ with the same value as _`arr[i]`_._ **Note:** `|x|` is the absolute value of `x`. **Example 1:** ``` **Input:** arr = [2,1,3,1,2,3,3] **Output:** [4,2,7,2,4,4,5] **Explanation:** - Index 0: Another 2 is found at index 4. |0 - 4| = 4 - Index 1: Another 1 is found at index 3. |1 - 3| = 2 - Index 2: Two more 3s are found at indices 5 and 6. |2 - 5| + |2 - 6| = 7 - Index 3: Another 1 is found at index 1. |3 - 1| = 2 - Index 4: Another 2 is found at index 0. |4 - 0| = 4 - Index 5: Two more 3s are found at indices 2 and 6. |5 - 2| + |5 - 6| = 4 - Index 6: Two more 3s are found at indices 2 and 5. |6 - 2| + |6 - 5| = 5 ``` **Example 2:** ``` **Input:** arr = [10,5,10,10] **Output:** [5,0,3,4] **Explanation:** - Index 0: Two more 10s are found at indices 2 and 3. |0 - 2| + |0 - 3| = 5 - Index 1: There is only one 5 in the array, so its sum of intervals to identical elements is 0. - Index 2: Two more 10s are found at indices 0 and 3. |2 - 0| + |2 - 3| = 3 - Index 3: Two more 10s are found at indices 0 and 2. |3 - 0| + |3 - 2| = 4 ``` **Constraints:** `n == arr.length` `1 <= n <= 105` `1 <= arr[i] <= 105` **Note:** This question is the same as 2615: Sum of Distances.",8 "test_case": [9 {10 "label": "Example 1",11 "input": "arr = [2,1,3,1,2,3,3]",12 "output": "[4,2,7,2,4,4,5] "13 },14 {15 "label": "Example 2",16 "input": "arr = [10,5,10,10]",17 "output": "[5,0,3,4] "18 }19 ],20 "constraints": [21 "n == arr.length",22 "1 <= n <= 105",23 "1 <= arr[i] <= 105"24 ],25 "python_template": "class Solution(object):\n def getDistances(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"\n ",26 "java_template": "class Solution {\n public long[] getDistances(int[] arr) {\n \n }\n}",27 "metadata": {28 "func_name": "getDistances"29 }30}