C++20 sections · 1024 units
Open in Course

Registration - Implementation

Complete solution


plaintext
function registration_system(requests)
 username_count := empty map from string to integer
 for each username in requests
 if username not in username_count then
 output "OK"
 username_count[username] := 0
 else
 count := username_count[username]
 output username + count
 username_count[username] := count + 1
 return

The map tracks state across all requests. Each username remembers how many times it appeared. Notice the pattern: check existence, then either insert or update.