Top Ten Largest Files
Problem statement
You are given parallel arrays paths and sizes, where each distinct file path has a non-negative byte size.
Return up to ten paths with the largest sizes, ordered by decreasing size. Break equal-size ties by lexicographically smaller path. When fewer than ten files are supplied, return all of them.
Design the selection so it can process a filesystem traversal as a stream without sorting every file.
Function
topTenLargestFiles(paths: String[], sizes: long[]) → String[]Examples
Example 1
paths = ["/a","/b","/c"]sizes = [5,12,7]return = ["/b","/c","/a"]All three files are returned from largest to smallest.
Example 2
paths = ["z","a","m"]sizes = [10,10,10]return = ["a","m","z"]Equal sizes use lexicographic path order.
Example 3
paths = []sizes = []return = []An empty traversal has no files.
Constraints
0 <= paths.length = sizes.length <= 200000.- Paths are distinct, nonempty strings.
0 <= sizes[i] <= 10^18.