A file system logs every folder change a user makes. `"../"` moves to the parent folder (staying put if already in the main folder), `"./"` stays in the current folder, and `"x/"` moves into the child folder `x`, which always exists. The user starts in the main folder. Given the list `logs`, return the minimum number of operations needed to go back to the main folder after all of them.
A file system logs every folder change a user makes. "../" moves to the parent folder (staying put if already in the main folder), "./" stays in the current folder, and "x/" moves into the child folder x, which always exists. The user starts in the main folder. Given the list logs, return the minimum number of operations needed to go back to the main folder after all of them.
Example 1:
Input: {"logs":["d1/","d2/","../","d21/","./"]}
Output: 2
Constraints:
1≤logs.length≤103
2≤logs[i].length≤10
logs[i] contains lowercase English letters, digits, . and /.
logs[i] follows the format described in the statement.
Folder names consist of lowercase English letters and digits.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"logs":["d1/","d2/","../","d21/","./"]}
logs: blue enters a child, red climbs up, grey stays
d1/
d2/
../
d21/
./
Start in the main folder at depth 0. Only the depth matters: each folder below main costs one "../" to climb back out.