Making File Names Unique
Given an array of strings names of size n, you will create n folders in your file system such that, at the i^th minute, you will create a folder with the name names[i].
Since two files cannot have the same name, if you enter a folder name that was previously used, the system will add a suffix to its name in the form (k), where k is the smallest positive integer such that the obtained name remains unique.
Return an array of strings of length n where ans[i] is the actual name the system will assign to the i^th folder when you create it.
names = ["pes","fifa","gta","pes(2019)"]["pes","fifa","gta","pes(2019)"]names = ["gta","gta(1)","gta","avalon"]["gta","gta(1)","gta(2)","avalon"]Constraints
- 1 <= names.length <= 5 * 10^4
- 1 <= names[i].length <= 20
- names[i] consists of lowercase English letters, digits, and/or round brackets.
Asked at 1 companies
Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.