Skip to content

Practice Longest Absolute File Path

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#388
LeetCode Problem

Longest Absolute File Path

Problem Statement

The string input encodes a valid file system: entries are separated by newline characters, and the number of leading tab characters gives an entry’s nesting depth. Names contain letters, digits, or spaces; files have a name.extension form, while directory names contain no dot. An absolute path joins its directory names and final file name with slashes. Return the greatest character length of such a file path, counting the slashes but not the encoding’s tabs or newlines. Return zero if there are no files. Every name is nonempty.

Source: Longest Absolute File Path on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
input = "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"
Output
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
32

# Example 3

Input
input = "a"
Output
0

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.

Related LeetCode Problems

Practice more problems similar to Longest Absolute File Path.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.