Cloud Storage System, Part 2: Largest Files
Reported by candidates from Ramp's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Ramp reported this one in May 2026, and it looks friendly until level 2 hits. The Cloud Storage System, Part 2: Largest Files, asks you to build an in-memory file store, then answer prefix queries for the top n biggest files. If you're taking this OA in the next day or two, the part that matters is GET_N_LARGEST, not the add and delete calls. It's a design problem with a sorting core, and the levels stack, so a sloppy level 1 hurts you later. StealthCoder is the safety net if you blank mid-assessment, but you should walk in knowing the shape of this.
The problem
Your task is to implement a simple cloud storage system. All operations that should be supported are listed below. Solving this task consists of several levels. Subsequent levels are opened when the current level is correctly solved. You always have access to the data for the current and all previous levels. Requirements Your task is to implement a simple cloud storage system that maps objects (files) to their metainformation. Specifically, the storage should maintain files and information about them, including each file name and size. This system is in-memory; it does not use the real filesystem. The levels are cumulative: Level 1 supports adding, retrieving, and deleting files. Level 2 displays the largest files matching a prefix. Level 3 adds capacity-limited users and user merging. Level 4 backs up and restores a user's files. To move to the next level, all tests at the current level must pass. Note The queries never call operations that produce a collision between a file name and a directory name. FastPrep Operation-Sequence Adapter FastPrep calls the function once with operations. Process the rows from left to right while preserving one shared storage state. Every row starts with an uppercase operation name followed by that method's string arguments. Return one string-array row for every input operation: Encode a Boolean as ["true"] or ["false"]. Encode an integer as one element, such as ["10"]. Encode None as an empty row []. Return the formatted list from GET_N_LARGEST directly; an empty list is also []. Multipart Series Part 1: File Operations Part 2: Largest Files Part 3: Users and Capacity Part 4: Backup and Restore Level 1: File Operations The cloud storage system should support file manipulation. add_file(self, name: str, size: int) -> bool adds a new file name to the storage. size is the amount of memory required in bytes. The operation fails if a file with the same name already exists. Return True if the file was added successfully or False otherwise. The adapter row is ["ADD_FILE", name, size]. Files added this way are owned by the unlimited admin user. get_file_size(self, name: str) -> int | None returns the size of file name if it exists, or None otherwise. The adapter row is ["GET_FILE_SIZE", name]. delete_file(self, name: str) -> int | None deletes file name. Return the deleted file size when deletion succeeds, or None if the file does not exist. The adapter row is ["DELETE_FILE", name]. Level 2: Largest Files Implement an operation for retrieving statistics about files with a specific prefix. get_n_largest(self, prefix: str, n: int) -> list[str] returns the names of the top n largest files whose names start with prefix, formatted as ["<name_1>(<size_1>)",..., "<name_n>(<size_n>)"]. Sort matching files by size in descending order. Break a size tie by file name in lexicographical ascending order. If there are no matching files, return an empty list. If fewer than n files match, return all of them in the specified format. The adapter row is ["GET_N_LARGEST", prefix, n]. The visible source table contains one malformed no-match call whose second argument is a file name even though the declared signature requires n: int. The judged contract follows the declared signature: n is an integer, and a prefix with no matches returns an empty row. Function cloudStorageLevel2(operations: String[][]) → String[][] Examples Example 1 operations = [["ADD_FILE","/dir1/dir2/file.txt","10"],["ADD_FILE","/dir1/dir2/file.txt","5"],["GET_FILE_SIZE","/dir1/dir2/file.txt"],["DELETE_FILE","/non-existing.file"],["DELETE_FILE","/dir1/dir2/file.txt"],["GET_FILE_SIZE","/not-existing.file"]] return = [["true"],["false"],["10"],[],["10"],[]] The first add succeeds, the duplicate add fails, and the existing file size is 10. Deleting a missing file returns None; deleting the existing file returns 10; the final lookup again returns None. Example 2 operations = [["ADD_FILE","/dir/file1.txt","5"],["ADD_FILE","/dir/file2","20"],["ADD_FILE","/dir/deeper/file3.mov","9"],["GET_N_LARGEST","/dir","2"],["GET_N_LARGEST","/dir/file","3"],["GET_N_LARGEST","/another_dir","3"],["ADD_FILE","/big_file.mp4","20"],["GET_N_LARGEST","/","2"]] return = [["true"],["true"],["true"],["/dir/file2(20)","/dir/deeper/file3.mov(9)"],["/dir/file2(20)","/dir/file1.txt(5)"],[],["true"],["/big_file.mp4(20)","/dir/file2(20)"]] Prefix filtering keeps matching names only. Size is the primary order; equal sizes are ordered lexicographically. The no-match query returns an empty row. Constraints Every operation row is well formed and uses an operation available at this level. Every numeric argument is a base-10 integer string whose value and all arithmetic results fit in a signed 64-bit integer. File names, prefixes, and user IDs are non-empty case-sensitive strings. The input never creates a collision between a file name and a directory name. All users share one global file-name namespace. The admin user exists initially and has unlimited capacity. Process operations in the supplied order. The storage starts empty.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The core is a hash map from file name to size, which handles ADD_FILE, GET_FILE_SIZE and DELETE_FILE in constant time. For GET_N_LARGEST, filter keys that start with the prefix, sort by size descending then name ascending, take the first n, and format each as name(size). A simple scan and sort is fine unless the tests push big inputs. Then reach for a heap of size n, or a trie with per-node data. The pitfalls are the tie-break (name ascending, not descending), returning an empty list on no match, and returning fewer than n when fewer match. Also remember the adapter format: booleans become ["true"], None becomes [], ints become single-element rows. Keep your storage clean because later levels add users and backups on top. If you freeze on the sort key or the output encoding during the live OA, StealthCoder can cover you.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Cloud Storage System, Part 2: Largest Files cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Ramp's OA.
Ramp reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Cloud Storage System, Part 2: Largest Files FAQ
What's the trick in Ramp's Largest Files question?+
Store files in a hash map, then for each prefix query filter, sort by size descending with name ascending as the tie-break, and slice to n. The trick is the comparator and the output format, not the data structure. Use a key like (-size, name) and you're done.
How hard is this really?+
Level 1 and 2 are easy to medium. The logic is short, but the adapter rules trip people up: empty rows for None, string-encoded booleans, and strings formatted as name(size). Most lost points come from format mistakes, not algorithms.
Do I need a trie for the prefix search?+
Usually not. A linear scan with startswith, then a sort, passes typical tests. A trie or heap helps only if inputs are large. Write the simple version first, since later levels build on it and correctness matters more than cleverness.
What edge cases should I test?+
Test a prefix with no matches, which returns []. Test fewer matches than n. Test equal sizes where names decide order. Test a deleted file no longer appearing in results. Test duplicate adds returning false without changing the stored size.
How do I prepare in 48 hours?+
Write this class from scratch once, with all three Level 1 operations and the prefix query. Practice the (-size, name) sort key and the output formatting. Then think about how users and backups could attach to your storage, since the levels are cumulative.