Homo or Hetero?
InterviewTime limit3sMemory limit256 MB
Maintain a list under insert and delete-first-occurrence operations and classify it after each step as homogeneous, heterogeneous, both, or neither.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation, Simulation
- Solved
- No attempts yet
Problem
You maintain a list of numbers that starts out empty and supports two operations:
insert number— appends the given number to the end of the list.delete number— removes the first occurrence of the given number. If the number is not in the list, the list is left unchanged.
For example, inserting into the list gives . Deleting from gives , while deleting from leaves it unchanged.
A list is homogeneous if it contains at least two equal numbers, and heterogeneous if it contains at least two different numbers. For example, is homogeneous, is heterogeneous, is both, and the empty list is neither.
Starting from the empty list, process a sequence of insert and delete operations and, after each one, report whether the list is homogeneous, heterogeneous, both, or neither.
Input
The first line contains an integer , the number of operations ().
Each of the next lines describes one operation: the word insert or delete, followed by an integer ().
Output
After each operation, print one line describing the state of the list:
both— the list is both homogeneous and heterogeneous.homo— the list is homogeneous but not heterogeneous.hetero— the list is heterogeneous but not homogeneous.neither— the list is neither homogeneous nor heterogeneous.