Registration System Problem
Registration System Problem — ExecCode Medium DSA Practice
Solve the Registration System problem on ExecCode. Free online medium DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
A registration system receives usernames one by one. A name can be stored only once. For each name, if it is not already registered, register it and answer OK. If it is already registered, register the name with the smallest positive integer suffix that is still free, and answer that new name. Return the answers in input order. You are given: words — usernames in arrival order Return one answer per username: OK, or the registered name with its suffix. The suffix is appended directly, with no space. Registering abacaba a second time produces abacaba1, and that string is then taken. A later request for the exact name abacaba1 must pick a different free suffix.
Examples
Input {'words': ['abacaba', 'acaba', 'abacaba', 'acab']}; Output ['OK', 'OK', 'abacaba1', 'OK']. Input {'words': ['a', 'a', 'a1']}; Output ['OK', 'a1', 'a11']. Input {'words': ['first', 'first', 'second']}; Output ['OK', 'first1', 'OK']
Constraints
1 <= words.length <= 100000 1 <= each name length <= 32 Names contain only lowercase English letters and digits
Practice Registration System free on ExecCode. Browse DSA problems, topic map, and placement guides.