Skip to content
Decoder

Crawler Log Folder

Easy

Problem

A file explorer logs every folder change as a string in logs. You start in the main folder. Each log is one of:

- "../": move to the parent folder. If you are already in the main folder, stay where you are. - "./": stay in the current folder. - "x/": move into the child folder named x (it always exists).

After all the operations, return the minimum number of moves needed to get back to the main folder.

Example 1

Input
logs = ["d1/", "d2/", "../", "d21/", "./"]
Output
2

Example 2

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

Example 3

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

Constraints

  • 1 <= logs.length <= 10^3
  • 2 <= logs[i].length <= 10
  • Folder names contain lowercase letters and digits.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.