Top Ten Largest Files
Updated
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 from largest size to smallest. 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.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Minimum Meeting Rooms Without a Sweep LineGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions