Tries, Contacts Hackerrank question

Question on Tries data structure- Hackerrank.

We’re going to make our own Contacts application! The application must perform two types of operations:

  1. add name, where is a string denoting a contact name. This must store as a new contact in the application.
  2. find partial, where is a string denoting a partial name to search the application for. It must count the number of contacts starting with and print the count on a new line.

Given sequential add and find operations, perform each operation in order.

Input Format

The first line contains a single integer, , denoting the number of operations to perform.
Each line of the subsequent lines contains an operation in one of the two forms defined above.

Constraints

  • 1<= n <= 10^5
  • 1<= | name | <= 21
  • 1<= | partial | <=21
  • It is guaranteed that and contain lowercase English letters only.
  • The input doesn’t have any duplicate for the operation.

Output Format

For each find partial operation, print the number of contact names starting with on a new line.

Leave a Reply

Your email address will not be published. Required fields are marked *