File Dashboard
MediumSorting · Atlassian
A file storage dashboard shows two numbers: the total size of every file processed, and the largest collections.
files is a list of rows [name, size, collections], where collections is a list of distinct collection names the file belongs to. A file may belong to several collections or to none. The size of a collection is the sum of the sizes of the files in it; a file in two collections counts toward both.
Return [total_size, top] where:
total_sizeis the sum of the sizes of all files, whether or not they are in a collection;toplists up tokcollections as[collection_name, collection_size]pairs, largest size first, with equal sizes ordered by name alphabetically. Only collections that contain at least one file exist, sotopmay be shorter thank.
Example 1
- Input:
- files = [["a.txt", 100, []], ["b.png", 300, ["photos", "trip"]], ["c.png", 200, ["photos"]], ["d.pdf", 450, ["work"]]], k = 2
- Output:
- [1050, [["photos", 500], ["work", 450]]]
- Explanation
- All four files add up to 1050.
photosholdsb.pngandc.png(500),workholdsd.pdf(450) andtripholdsb.png(300). The two largest arephotosandwork;a.txtcounts only toward the total.
Example 2
- Input:
- files = [["x.log", 50, ["logs"]], ["y.log", 70, ["logs", "audit"]], ["z.csv", 120, ["audit"]]], k = 5
- Output:
- [240, [["audit", 190], ["logs", 120]]]
- Explanation
y.logbelongs to both collections, so it is counted in each:auditis 70 + 120 = 190 andlogsis 50 + 70 = 120. Only two collections exist, sok = 5returns both.
Example 3
- Input:
- files = [["notes.md", 10, []]], k = 3
- Output:
- [10, []]
- Explanation
- The file is not in any collection, so the total is 10 and the list is empty.
Constraints
0 <= files.length <= 10^50 <= size <= 10^9- Each file is in at most 10 collections
0 <= k <= 10^5