Check duplicates in a stream of strings
Check duplicates in a stream of strings
Given an array arr[] of strings containing the names of employees in a company. Assuming that the names are being entered in a system one after another, the task is to check whether the current name is entered for the first time or not.
Examples:
Input: arr[] = {“geeks”, “for”, “geeks”}
Output:
No
No
Yes
Approach: Create an unordered_set to store the names of the employees and start traversing the array, if the current name is already present in the set then print Yes else print No and insert it into the set.
Below is the implementation of the above approach:
Output:
No No Yes
Output:
No No Yes
Output:
No No Yes
Comments
Post a Comment