Understand what the interviewer is asking for by using test cases and questions about the problem.
souvenirs
.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Count the occurrences of each souvenir, then check if these counts are unique.
1) Count the occurrences of each souvenir in `souvenirs` using a dictionary.
2) Track the counts in a set to check for uniqueness.
3) If all counts are unique, return `True`; otherwise, return `False`.
⚠️ Common Mistakes
def unique_souvenir_counts(souvenirs):
# Create a dictionary to count the number of each souvenir
count_dict = {}
for souvenir in souvenirs:
if souvenir in count_dict:
count_dict[souvenir] += 1
else:
count_dict[souvenir] = 1
# Create a set to track the counts we've seen
seen_counts = set()
# Check if all counts are unique
for count in count_dict.values():
if count in seen_counts:
return False
seen_counts.add(count)
return True