#K39867. Longest Absolute File Path
Longest Absolute File Path
Longest Absolute File Path
Given a file system represented as a string where each directory or file is separated by a newline character ('\n') and the depth of each entry is indicated by the number of tab characters ('\t') preceding its name, compute the length of the longest absolute path to a file in the file system. A file is identified by having a period ('.') in its name. The absolute path is constructed by joining all directory names and the file name with a '/' between them. If there is no file in the system, the output should be 0.
For example, consider the following file system representation:
dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext
The longest absolute file path is "dir/subdir2/file.ext" which has a length of 20.
The problem may be mathematically expressed as finding the maximum over all file paths: $$\max_{\text{file } f} ;\text{length}(\text{path}_{f})$$ where the length counts the characters in the path including the '/' separators.
inputFormat
The input consists of a file system represented as a string provided via standard input (stdin). The string contains directory and file names separated by newline characters ('\n') and uses tab characters ('\t') to indicate the depth of each entry.
outputFormat
Output a single integer to standard output (stdout), representing the length of the longest absolute path to any file in the file system. If no file is present, output 0.## sample
dir
subdir1
subdir2
file.ext
20