Medium · Streams & I/O
Find files size larger than 5M
Given the path of a root directory, walk its tree and return the sorted paths of every regular file strictly larger than 5 MiB (5 × 1024 × 1024 = 5,242,880 bytes); directories and symbolic links are never counted. Examples model the filesystem as path/size/isDir entries for visualization; the solution receives the root path.
Examples
Example 1
{
"entries": [
{"path": "root", "size": 0, "isDir": true},
{"path": "root/small.txt", "size": 1024, "isDir": false},
{"path": "root/big.bin", "size": 6291456, "isDir": false},
{"path": "root/medium.dat", "size": 3145728, "isDir": false},
{"path": "root/huge.zip", "size": 10485760, "isDir": false}
]
}Output: [root/big.bin, root/huge.zip]
Example 2
{
"entries": [
{"path": "root", "size": 0, "isDir": true},
{"path": "root/a.txt", "size": 100, "isDir": false},
{"path": "root/b.txt", "size": 200, "isDir": false}
]
}Output: []
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.