Skip to content

Practice Find the Distinct Difference Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2670
LeetCode Problem

Find the Distinct Difference Array

Problem Statement

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.

Source: Find the Distinct Difference Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3,4,5]
Output
[-3,-1,1,3,5]

# Example 2

Input
nums = [3,2,3,4,2]
Output
[-2,-1,0,2,3]

Constraints

1 <= n == nums.length <= 50
1 <= nums[i] <= 50

Related LeetCode Problems

Practice more problems similar to Find the Distinct Difference Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.