Longest Absolute File Path
Suppose we have a file system that stores both files and directories. In text form, the file system is represented by a string where:
\nseparates files and directories on different lines.\tindicates the depth level of a file or directory.- Every file and directory has a unique absolute path, formed by joining the directory names needed to reach it with
/separators. - Each directory name consists of letters, digits, and/or spaces.
- Each file name is of the form
name.extension, wherenameandextensionconsist of letters, digits, and/or spaces.
Given a string input representing the file system in this format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.
Note that the test cases are generated such that the file system is valid and no file or directory name has length 0.
Example 1
Input
input = "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"Output
20We have only one file, and the absolute path is "dir/subdir2/file.ext" of length 20.
Example 2
Input
input = "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext"Output
32The longest file path is "dir/subdir2/subsubdir2/file2.ext" of length 32.
Constraints
- 1 <= input.length <= 10^4
- input may contain lowercase or uppercase English letters, a new line character '\n', a tab character '\t', a dot '.', a space ' ', and digits.
- All file and directory names have positive length.