4. Find the Group with the Most Distinct Items
1. Description
You are given a sequence of logs containing two types of operations:
- switch group: changes the current group.
- push item: adds an item to the current group. Adding the same item to the same group multiple times only counts once.
Return the name of the group that contains the largest number of distinct items after processing all logs.
2. Solution
n = logs.size()
Time complexity: O(n)
Space complexity: O(n)
| |