The Crawler Log Folder interview question simulates a user navigating through a file system using terminal commands. You are given an array of strings logs, where:
"../" moves you to the parent folder."./" keeps you in the current folder."x/" moves you into a child folder named x.
You start in the main (root) folder. Your task is to find the minimum number of operations needed to return to the root folder after executing all the commands in the log.Companies like Amazon and Bloomberg use this simulation interview pattern to test basic logic and edge-case handling. It’s an "Easy" difficulty problem that evaluates whether you can maintain a "depth" state and handle boundary conditions (like trying to go up from the root). It's a fundamental exercise in string parsing and state management.
This problem is best solved using a Counter or a Stack.
depth = 0."../", decrement depth (but don't go below 0)."./", do nothing.depth.depth is the number of steps needed to return to the root.Logs: ["d1/", "d2/", "../", "d21/", "./"]
depth = 1.depth = 2.depth = 1.depth = 2.depth = 2.
Result: 2.depth > 0 before decrementing, leading to incorrect results if the log tries to go "above" the root."../" and "./".Always look for ways to simplify the state. If the problem only asks for "how many steps back," you don't need to know the names of the folders you visited, only how deep you are. This saves both time and space.