Crawler Log Folder

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.

30:00

Crawler Log Folder
easy
Free written solution
Topics
Companies

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≤1031 \leq logs.\text{length} \leq 10^3

  • 2≤logs[i].length≤102 \leq logs[i].\text{length} \leq 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.

current path (the stack of open folders)

deepest 0

main

depth 0
logs read 0 / 5
Variables
VariableValue
depth0
DepthFunction Call
Stack empty
0/11