Crawler Log Folder
Description
The Leetcode file system logs folder changes. "../" moves to parent, "./" stays in current, "x/" moves to child x. Return minimum operations to return to main folder.
Examples
logs = ["d1/","d2/","../","d21/","./"]2Path trace: d1/ (depth 1) → d2/ (depth 2) → ../ (depth 1) → d21/ (depth 2) → ./ (stays at 2). Need 2 '../' operations to return to main.
logs = ["../","./","d3/","d4/","../","d5/"]2Start at main folder (0). '../' at main stays at 0. './' stays at 0. 'd3/' goes to depth 1. 'd4/' goes to depth 2. '../' goes back to depth 1. 'd5/' goes to depth 2. Final depth is 2.
logs = ["d1/","d2/","d3/","../","../","../"]0Start at main folder (0). 'd1/' goes to depth 1. 'd2/' goes to depth 2. 'd3/' goes to depth 3. First '../' goes to depth 2. Second '../' goes to depth 1. Third '../' goes to depth 0 (main folder). Final depth is 0.
Constraints
- •
1 ≤ logs.length ≤ 10³
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.