Skip to content

Commit 97384d6

Browse files
committed
1948. Delete Duplicate Folders in System: RETRY
1 parent 1cb5265 commit 97384d6

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

Diff for: src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1469,3 +1469,4 @@ mod s1944_number_of_visible_people_in_a_queue;
14691469
mod s1945_sum_of_digits_of_string_after_convert;
14701470
mod s1946_largest_number_after_mutating_substring;
14711471
mod s1947_maximum_compatibility_score_sum;
1472+
mod s1948_delete_duplicate_folders_in_system;
+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* [1948] Delete Duplicate Folders in System
3+
*
4+
* Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the i^th folder in the file system.
5+
*
6+
* For example, ["one", "two", "three"] represents the path "/one/two/three".
7+
*
8+
* Two folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.
9+
*
10+
* For example, folders "/a" and "/b" in the file structure below are identical. They (as well as their subfolders) should all be marked:
11+
*
12+
* /a
13+
* /a/x
14+
* /a/x/y
15+
* /a/z
16+
* /b
17+
* /b/x
18+
* /b/x/y
19+
* /b/z
20+
*
21+
*
22+
* However, if the file structure also included the path "/b/w", then the folders "/a" and "/b" would not be identical. Note that "/a/x" and "/b/x" would still be considered identical even with the added folder.
23+
*
24+
* Once all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.
25+
* Return the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.
26+
*
27+
* Example 1:
28+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/19/lc-dupfolder1.jpg" style="width: 200px; height: 218px;" />
29+
* Input: paths = [["a"],["c"],["d"],["a","b"],["c","b"],["d","a"]]
30+
* Output: [["d"],["d","a"]]
31+
* Explanation: The file structure is as shown.
32+
* Folders "/a" and "/c" (and their subfolders) are marked for deletion because they both contain an empty
33+
* folder named "b".
34+
*
35+
* Example 2:
36+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/19/lc-dupfolder2.jpg" style="width: 200px; height: 355px;" />
37+
* Input: paths = [["a"],["c"],["a","b"],["c","b"],["a","b","x"],["a","b","x","y"],["w"],["w","y"]]
38+
* Output: [["c"],["c","b"],["a"],["a","b"]]
39+
* Explanation: The file structure is as shown.
40+
* Folders "/a/b/x" and "/w" (and their subfolders) are marked for deletion because they both contain an empty folder named "y".
41+
* Note that folders "/a" and "/c" are identical after the deletion, but they are not deleted because they were not marked beforehand.
42+
*
43+
* Example 3:
44+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/19/lc-dupfolder3.jpg" style="width: 200px; height: 201px;" />
45+
* Input: paths = [["a","b"],["c","d"],["c"],["a"]]
46+
* Output: [["c"],["c","d"],["a"],["a","b"]]
47+
* Explanation: All folders are unique in the file system.
48+
* Note that the returned array can be in a different order as the order does not matter.
49+
*
50+
*
51+
* Constraints:
52+
*
53+
* 1 <= paths.length <= 2 * 10^4
54+
* 1 <= paths[i].length <= 500
55+
* 1 <= paths[i][j].length <= 10
56+
* 1 <= sum(paths[i][j].length) <= 2 * 10^5
57+
* path[i][j] consists of lowercase English letters.
58+
* No two paths lead to the same folder.
59+
* For any folder not at the root level, its parent folder will also be in the input.
60+
*
61+
*/
62+
pub struct Solution {}
63+
64+
// problem: https://leetcode.com/problems/delete-duplicate-folders-in-system/
65+
// discuss: https://leetcode.com/problems/delete-duplicate-folders-in-system/discuss/?currentPage=1&orderBy=most_votes&query=
66+
67+
// submission codes start here
68+
69+
impl Solution {
70+
pub fn delete_duplicate_folder(paths: Vec<Vec<String>>) -> Vec<Vec<String>> {
71+
vec![]
72+
}
73+
}
74+
75+
// submission codes end
76+
77+
#[cfg(test)]
78+
mod tests {
79+
use super::*;
80+
81+
#[test]
82+
#[ignore]
83+
fn test_1948_example_1() {
84+
let paths = vec![
85+
vec_string!["a"],
86+
vec_string!["c"],
87+
vec_string!["d"],
88+
vec_string!["a", "b"],
89+
vec_string!["c", "b"],
90+
vec_string!["d", "a"],
91+
];
92+
93+
let result = vec![
94+
vec_string!["c"],
95+
vec_string!["c", "d"],
96+
vec_string!["a"],
97+
vec_string!["a", "b"],
98+
];
99+
100+
assert_eq!(Solution::delete_duplicate_folder(paths), result);
101+
}
102+
103+
#[test]
104+
#[ignore]
105+
fn test_1948_example_2() {
106+
let paths = vec![
107+
vec_string!["a"],
108+
vec_string!["c"],
109+
vec_string!["a", "b"],
110+
vec_string!["c", "b"],
111+
vec_string!["a", "b", "x"],
112+
vec_string!["a", "b", "x", "y"],
113+
vec_string!["w"],
114+
vec_string!["w", "y"],
115+
];
116+
117+
let result = vec![
118+
vec_string!["c"],
119+
vec_string!["c", "b"],
120+
vec_string!["a"],
121+
vec_string!["a", "b"],
122+
];
123+
124+
assert_eq!(Solution::delete_duplicate_folder(paths), result);
125+
}
126+
127+
#[test]
128+
#[ignore]
129+
fn test_1948_example_3() {
130+
let paths = vec![
131+
vec_string!["a", "b"],
132+
vec_string!["c", "d"],
133+
vec_string!["c"],
134+
vec_string!["a"],
135+
];
136+
137+
let result = vec![
138+
vec_string!["c"],
139+
vec_string!["c", "d"],
140+
vec_string!["a"],
141+
vec_string!["a", "b"],
142+
];
143+
144+
assert_eq!(Solution::delete_duplicate_folder(paths), result);
145+
}
146+
}

0 commit comments

Comments
 (0)