🔥✅✅ Dart Solution 📌📌 || with Explanation 👌👌
Solution
Prefix Calculation: We iterate through the array from the start to the end, adding each element to a set and recording the size of the set at each inde
# Solution

1. **Prefix Calculation**: We iterate through the array from the start to the end, adding each element to a set and recording the size of the set at each index. This gives us the number of distinct elements in the prefix up to that index.
2. **Suffix Calculation**: We iterate through the array from the end to the start, adding each element to a set and recording the size of the set at each index. This gives us the number of distinct elements in the suffix starting from that index.
3. **Difference Calculation**: For each index, we subtract the suffix distinct count from the prefix distinct count to get the value for the distinct difference array.

### Time Complexity

- **Prefix Calculation**: We can calculate the prefix distinct counts in a single pass through the array using a set to keep track of unique elements. This takes `O(n)` time.
- **Suffix Calculation**: Similarly, we can calculate the suffix distinct counts in a single pass through the array from the end to the start, also using a set. This also takes `O(n)` time.
- **Overall Time Complexity**: The overall time complexity is `O(n)` because we are making two passes through the array.

```dart
class Solution {
  List<int> distinctDifferenceArray(List<int> nums) {
    int n = nums.length;
    List<int> diff = List.filled(n, 0);
    Set<int> prefixSet = {};
    List<int> prefixCounts = List.filled(n, 0);
    for (int i = 0; i < n; i++) {
        prefixSet.add(nums[i]);
        prefixCounts[i] = prefixSet.length;
    }
    Set<int> suffixSet = {};
    List<int> suffixCounts = List.filled(n, 0);
    for (int i = n - 1; i >= 0; i--) {
        suffixCounts[i] = suffixSet.length;
        suffixSet.add(nums[i]);
    }
    for (int i = 0; i < n; i++) {
        diff[i] = prefixCounts[i] - suffixCounts[i];
    }
    return diff;
    }
}
```
['Dart']