For the below file system, the string S will be:
S = βdir\n\tsubdir1\n\t\tfile1.txt\n\t\tfile2.txt\n\tfile.txtβ
dir
subdir1
file1.txt
file2.txt
file.txt
file2.txt has an absolute path βdir/subdir1/file2.txtβ and file.txt has path βdir/file.txtβ.
The absolute file path length is the length of this string.
So absolute path length for file file2.txt will be the length of string βdir/subdir1/file2.txtβ which is 21.
If there is no file in the system, return 0.
The first line of the input contains the string βSβ.
The first line of each input contains an integer that denotes the number of lines that will be given but this integer is not passed to the function because one of the aim of this question is to read input until EOF(End of the file).
The only line of output prints a single integer denoting the longest absolute file path.
0 <= |S| <= 5 * 10^3
Where |S| denotes the length of string S
Time limit: 1 sec
The key idea in this approach is to traverse the string line by line and count the number of tabs to get the depth of the current directory/file while maintaining a stack that stores all previous directories needed to reach the current directory/file.
Algorithm: