Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 543 Bytes

File metadata and controls

27 lines (22 loc) · 543 Bytes

What Did I Learn?

In this challenge I learned:

  1. Empty dict to count different elements
prefix = defaultdict(int)
  1. Counts the frequency of the elements in the suffix (the entire list initially)
suffix = Counter(nums)
  1. 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]
  1. Add the resulting one by one in the result list
result.append(len(prefix) - len(suffix))