Longest Absolute File Path - Past Goolge Interview

Problem

leetcode.com

We are given a string as a file path like this: "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext". This string means directory structure below.

We answer a number of max length of file path like this: 20 (number of length about dir/subdir2/file.ext)

How to Solve

Number of \t means depth of directory or file. Using Stack, we can control length of file path and depth of directory or file.

Source Code

Points

  • Number of stack size and number of depth of directory or file are equivalent
  • In case of that same depth directories or files continue, we pop value from stack in oder to find out parent directory.