Skip to content

Crawler Log Folder

EasyStack
Decode it first. Clues, constraints, pattern and plan before any code.

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.

logs = ["d1/", "d2/", "../", "d21/", "./"]          →  2
logs = ["d1/", "d2/", "./", "d3/", "../", "d31/"]    →  3
logs = ["d1/", "../", "../", "../"]                 →  0

Constraints

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