- Empty dict to count different elements
prefix = defaultdict(int)- Counts the frequency of the elements in the suffix (the entire list initially)
suffix = Counter(nums)- Add elements on the empty list and removing from the full list
for x in nums:
prefix[x] += 1
suffix[x] -= 1
if suffix[x] == 0:
del suffix[x]- Add the resulting one by one in the result list
result.append(len(prefix) - len(suffix))