2670. Find the Distinct Difference Array
You are given a 0-indexed array
nums
of lengthn
.The distinct difference array of
nums
is an arraydiff
of lengthn
such thatdiff[i]
is equal to the number of distinct elements in the suffixnums[i + 1, ..., n - 1]
subtracted from the number of distinct elements in the prefixnums[0, ..., i]
.Return the distinct difference array of
nums
.Note that
nums[i, ..., j]
denotes the subarray ofnums
starting at indexi
and ending at indexj
inclusive. Particularly, ifi > j
thennums[i, ..., j]
denotes an empty subarray.
1 | class Solution { |