Find Top 5 Largest Files in a Directory Tree
You are given two APIs: def list_dir(path: str) -> List[str]: """ Given a path, return the list of entries inside the directory. Return [] or raise an exception if the path is not a directory. """ pass def size_of(path: str) -> int: """ Given a file path, return its size in bytes. Raise an exception or return -1 if it's a directory. """ pass Implement the function: def get_top_5_largest_files(path: str) -> List[Tuple[int, str]]: """ Return a list of the top 5 largest files in the directory tree rooted at path. Each element is a tuple of (file_size, file_path). """ Constraints: You can assume there are no symbolic links (no cycles). Files and directories are represented as absolute paths (e.g., "/root/folder1/file.txt"). You must handle nested directories. You can assume there are no permission issues and paths are accessible.
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late June, 2025
Junior
Hello Interview Premium
Your account is free and you can post anonymously if you choose.