Crawler Log Folder

EasyStacksimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A file-system session starts in the root folder. The array logs records the folder commands that were run, in order: - "../" moves to the parent folder; if already at the root, nothing happens. - "./" stays in the current folder. - "x/" moves into the child folder named x (which always exists). Return the minimum number of commands needed to get back to the root folder after all logs have run - that is, how many levels below the root the session ends.

Examples

Input: logs = ["d1/","d2/","../","d21/","./"]
Output: 2
The session ends in d1/d21, two levels below the root.
Input: logs = ["d1/","../","../","../"]
Output: 0
Extra "../" commands at the root have no effect.

Constraints

  • 1 <= logs.length <= 1000
  • 2 <= logs[i].length <= 10
  • `logs[i]` is "../", "./", or a folder name of lowercase letters and digits followed by "/"
  • Folder names never consist solely of dots

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems