Editorial for TLE '16 Contest 3 P1 - Hapax Legomenon


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

This problem is a simple implementation problem; simply count the number of strings that only appear once in the given list.

We can use a map to accomplish this by incrementing mp[string] for each string. After, we can iterate through the map keys and check which strings have a value of 1.

There is a less efficient way to accomplish the task, but it does not require a map and it will pass all of the cases. We simply keep track of all previous strings and keep track if a string has been duplicated or not. When we input a string, compare it to all previous strings. If we find that a string already exists, flag both strings that they have been duplicated. Afterward, count the number of strings that have not been flagged.

Time Complexity: \mathcal{O}(N) or \mathcal{O}(N^2)


Comments

There are no comments at the moment.