I parsed the depth fine using the tab count but then fumbled on tracking cumulative path lengths per depth level.
Use a stack to maintain the cumulative path length at each directory depth. For each line, compute its depth by counting leading tabs, then update the stack: if the line is a file, calculate the total path length; if it's a directory, push the new cumulative length. Keep track of the maximum file path length seen.
Pro tip: Clarify that the path length includes the '/' separators between components, and that only files (not directories) count. Also, mention that you assume the input is well-formed (e.g., no empty lines) but can handle edge cases like no files.
Split the string by newline characters to get each entry. For each entry, determine its depth by counting the number of leading tab characters.
Use a stack where each element represents the cumulative length of the path up to that depth. When processing a line at depth d, ensure the stack size is d+1 (pop extra elements if needed).
For a directory, push the new cumulative length (previous length + name length + 1 for '/'). For a file, compute the total length (previous length + name length) and update the maximum if larger.
After processing all lines, return the maximum length found, or 0 if no files were encountered.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.