1487. Making File Names Unique Medium
1/**
2 * [1487] Making File Names Unique
3 *
4 * 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].
5 * 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.
6 * 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.
7 *
8 * Example 1:
9 *
10 * Input: names = ["pes","fifa","gta","pes(2019)"]
11 * Output: ["pes","fifa","gta","pes(2019)"]
12 * Explanation: Let's see how the file system creates folder names:
13 * "pes" --> not assigned before, remains "pes"
14 * "fifa" --> not assigned before, remains "fifa"
15 * "gta" --> not assigned before, remains "gta"
16 * "pes(2019)" --> not assigned before, remains "pes(2019)"
17 *
18 * Example 2:
19 *
20 * Input: names = ["gta","gta(1)","gta","avalon"]
21 * Output: ["gta","gta(1)","gta(2)","avalon"]
22 * Explanation: Let's see how the file system creates folder names:
23 * "gta" --> not assigned before, remains "gta"
24 * "gta(1)" --> not assigned before, remains "gta(1)"
25 * "gta" --> the name is reserved, system adds (k), since "gta(1)" is also reserved, systems put k = 2. it becomes "gta(2)"
26 * "avalon" --> not assigned before, remains "avalon"
27 *
28 * Example 3:
29 *
30 * Input: names = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]
31 * Output: ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]
32 * Explanation: When the last folder is created, the smallest positive valid k is 4, and it becomes "onepiece(4)".
33 *
34 *
35 * Constraints:
36 *
37 * 1 <= names.length <= 5 * 10^4
38 * 1 <= names[i].length <= 20
39 * names[i] consists of lowercase English letters, digits, and/or round brackets.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/making-file-names-unique/
45// discuss: https://leetcode.com/problems/making-file-names-unique/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn get_folder_names(names: Vec<String>) -> Vec<String> {
51 vec![]
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1487() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.