C++20 sections · 1024 units
Open in Course

Registration - Algorithm

Breaking it down

Here's your approach:

1.1. Read nn, the number of registration requests.

2.2. Create an empty map from string to integer.

3.3. For each of the nn requests, read the username.

4.4. Check if the username exists in the map.

5.5. If not found, output OK and insert username with value 0.

6.6. If found, get its count, output username concatenated with count, then increment the count in the map. This solution processes each request in O(logn)O(\log n) time for map operations, giving you O(nlogn)O(n \log n) total time. Maps provide fast lookup and update, making the solution both clean and fast.