from typing import List
from typing import Tuple


def longest_path(dir_str: str) -> str:
    """
    To find the longest path to any dir/file.
    Can be easily modified to get the longest path to just a file

    :param dir_str: Directory string containing the directory structure
    :return: longest directory path (number of characters) to any file
    """

    def util(dirs: List[str], prefix: str) -> Tuple[str, int]:
        nonlocal index, l

        if not dirs:
            return "", 0

        max_len = 0
        return_str = ""

        while index < l:
            cur = dirs[index]

            if cur.startswith(prefix):
                cur = cur.lstrip(prefix)
                index += 1
                sub_str, sub_len = util(dirs, prefix + "\t")

                if sub_len + len(cur) + 1 > max_len:
                    if sub_len:
                        max_len = sub_len + len(cur) + 1
                        return_str = cur + "/" + sub_str
                    else:
                        max_len = len(cur)
                        return_str = cur
            else:
                break

        return return_str, max_len

    if not dir_str:
        return ""

    all_dirs = dir_str.split("\n")
    index: int = 0
    l: int = len(all_dirs)

    return util(all_dirs, "")[0]