Find the Distinct Difference Array
|
|
Here’s a brief explanation of the code:
cnt
is an array that keeps track of the count of each element innums
.dist
keeps track of the number of distinct elements in the suffix.- The first loop computes the cumulative count of distinct elements from the beginning of the array and stores it in
res
. - The second loop modifies the result by considering the distinct elements in the suffix.
- The
exchange
part of the original code is implemented using separate statements in Python.