{ "id": 2777, "name": "find_the_distinct_difference_array", "difficulty": "Easy", "link": "https://leetcode.com/problems/find-the-distinct-difference-array/", "date": "2023-04-30 00:00:00", "task_description": "You are given a **0-indexed** array `nums` of length `n`. The **distinct difference** array of `nums` is an array `diff` of length `n` such that `diff[i]` is equal to the number of distinct elements in the suffix `nums[i + 1, ..., n - 1]` **subtracted from** the number of distinct elements in the prefix `nums[0, ..., i]`. Return _the **distinct difference** array of _`nums`. Note that `nums[i, ..., j]` denotes the subarray of `nums` starting at index `i` and ending at index `j` inclusive. Particularly, if `i > j` then `nums[i, ..., j]` denotes an empty subarray. **Example 1:** ``` **Input:** nums = [1,2,3,4,5] **Output:** [-3,-1,1,3,5] **Explanation:** For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3. For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1. For index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1. For index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3. For index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5. ``` **Example 2:** ``` **Input:** nums = [3,2,3,4,2] **Output:** [-2,-1,0,2,3] **Explanation:** For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2. For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1. For index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0. For index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2. For index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3. ``` **Constraints:** `1 <= n == nums.length <= 50` `1 <= nums[i] <= 50`", "public_test_cases": [ { "label": "Example 1", "input": "nums = [1,2,3,4,5]", "output": "[-3,-1,1,3,5] " }, { "label": "Example 2", "input": "nums = [3,2,3,4,2]", "output": "[-2,-1,0,2,3] " } ], "private_test_cases": [ { "input": [ 44, 1, 46, 10, 5, 7, 50, 2, 44, 32, 1, 26, 34, 21, 33, 30, 5, 6, 33, 12, 13, 1, 37 ], "output": [ -17, -16, -14, -12, -11, -9, -7, -5, -4, -2, -2, 0, 2, 4, 5, 7, 8, 10, 11, 13, 15, 16, 18 ] }, { "input": [ 37 ], "output": [ 1 ] }, { "input": [ 17, 31, 15, 24, 8, 5, 41, 12, 33, 23, 44, 3, 33, 45, 45, 44, 35, 37, 2, 31, 11, 38, 5, 10, 4, 48, 35, 1, 40, 3, 13 ], "output": [ -22, -21, -19, -17, -15, -14, -12, -10, -9, -7, -6, -5, -4, -3, -2, -1, 0, 2, 4, 5, 7, 9, 10, 12, 14, 16, 17, 19, 21, 22, 24 ] }, { "input": [ 13, 1, 39, 29, 17, 39 ], "output": [ -3, -1, 0, 2, 4, 5 ] }, { "input": [ 14, 21, 34, 43, 2, 3, 48, 17, 1, 16, 40, 50, 27, 36, 6, 28, 26, 2, 44, 33, 43, 6, 13, 20, 21, 4, 6, 41, 38, 19, 39, 42, 14, 7, 35, 4, 39, 12, 6, 10, 25, 18 ], "output": [ -32, -31, -29, -28, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -8, -6, -4, -3, -1, 1, 2, 2, 4, 6, 7, 8, 8, 10, 12, 14, 15, 17, 18, 20, 22, 23, 24, 26, 27, 29, 31, 33 ] }, { "input": [ 10, 8, 44, 4, 33, 21, 50, 46, 29, 41, 45, 24, 30, 10, 43, 29, 38, 31, 14, 7, 3, 19, 27, 32, 5, 43, 24, 32, 6, 15, 24 ], "output": [ -24, -22, -20, -18, -16, -14, -12, -10, -9, -7, -5, -4, -2, -1, 0, 1, 3, 5, 7, 9, 11, 13, 15, 16, 18, 19, 19, 20, 22, 24, 25 ] }, { "input": [ 2, 2, 1, 39, 18, 15, 15, 3, 18, 4, 47, 6, 8, 26, 28, 37, 30, 4, 22, 2, 12, 12, 32, 13, 18, 39, 13 ], "output": [ -17, -17, -15, -14, -13, -12, -11, -9, -9, -8, -6, -4, -2, 0, 2, 4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 18 ] }, { "input": [ 44, 41, 17, 11, 3, 21, 7, 1, 23, 48, 39, 41, 44, 26, 28, 46, 46, 9, 5, 29, 38, 5, 1, 4, 17 ], "output": [ -18, -17, -16, -14, -12, -10, -8, -7, -5, -3, -1, 0, 1, 3, 5, 6, 7, 9, 10, 12, 14, 15, 16, 18, 19 ] }, { "input": [ 19, 35, 2, 8, 30, 46 ], "output": [ -4, -2, 0, 2, 4, 6 ] }, { "input": [ 19, 41, 16, 40, 20 ], "output": [ -3, -1, 1, 3, 5 ] } ], "haskell_template": "distinctDifferenceArray :: [Int] -> [Int]\ndistinctDifferenceArray nums ", "ocaml_template": "let distinctDifferenceArray (nums: int list) : int list = ", "scala_template": "def distinctDifferenceArray(nums: List[Int]): List[Int] = { \n \n}", "java_template": "class Solution {\n public int[] distinctDifferenceArray(int[] nums) {\n \n }\n}", "python_template": "class Solution(object):\n def distinctDifferenceArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n " }