Crawler Log Folder

Crawler Log Folder is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Stack Patterns pattern, in the Simulation / Backtracking Helper subpattern.

Problem statement

The Leetcode file system keeps a log each time some user performs a change folder operation.

The operations are described below: "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).

"./" : Remain in the same folder.

"x/" : Move to the child folder named x (This folder is guaranteed to always exist).

You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.

The file system starts in the main folder, then the operations in logs are performed.

Return the minimum number of operations needed to go back to the main folder after the change folder operations.

Example 1: Input: logs = ["d1/","d2/","../","d21/","./"] Output: 2 Explanation: Use this change folder operation "../" 2 times and go back to the main folder.

Example 2: Input: logs = ["d1/","d2/","./","d3/","../","d31/"] Output: 3

Example 3: Input: logs = ["d1/","../","../","../"] Output: 0

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.

Topics and companies

Topics: Stack.

Reported in interviews at Mercari.

How to practise Crawler Log Folder on Thita.ai

Starter code is provided in C, C#, C++, dart, elixir, erlang, Go, Java, JavaScript, Kotlin, PHP, Python, python3, racket, Ruby, Rust, Scala, Swift and TypeScript. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n) time and O(1) space.

Open Crawler Log Folder in the code editor, or read the Crawler Log Folder editorial for a worked solution with its approach and complexity analysis.

Where Crawler Log Folder sits in the DSA pattern sheet

Problems related to Crawler Log Folder

Other problems that use the same Simulation / Backtracking Helper and Stack Patterns techniques:

Preparing this workspace.