Find the Largest Files
As an ambitious data scientist at a large tech company, you've been handed the task of managing an overwhelmingly large volume of data. Your team works with numerous files spread across several directories and subdirectories, making it difficult to keep track of the files and their sizes. There's a growing need for a program that can traverse through a main directory, including all of its subdirectories, sort all the files from largest to smallest based on their size, and output a list of the files.
The program will receive a single input - the path of the directory. The program should print a list of the files in descending order of their size. Each line of the output should contain the file's path relative to the provided directory and its size in bytes, separated by a space.
Input | Output |
documents | project/data.csv 5000
project/notes.txt 3000
project/data2.csv 2500
presentation/pres1.ppt 2000
presentation/pres2.ppt 1500
draft.txt 1000
README.md 500 |
Note that the directory structure can have several levels of nested directories.
Note: You can search online on how to get the size of a file using
pathlib
.Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB