Skip to content

Practice Making File Names Unique

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1487
LeetCode Problem

Making File Names Unique

Problem Statement

Given an array of strings names of size n. You will create n folders in your file system such that, at the ith 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 have a suffix addition to its name in the form of (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 ith folder when you create it.

Source: Making File Names Unique on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
names = ["pes","fifa","gta","pes(2019)"]
Output
["pes","fifa","gta","pes(2019)"]

# Example 2

Input
names = ["gta","gta(1)","gta","avalon"]
Output
["gta","gta(1)","gta(2)","avalon"]

# Example 3

Input
names = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]
Output
["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]

Constraints

1 <= names.length <= 5 * 10^4
1 <= names[i].length <= 20
names[i] consists of lowercase English letters, digits, and/or round brackets.

Related LeetCode Problems

Practice more problems similar to Making File Names Unique.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.