← 返回 ramp 的题目列表OA — Cloud File-Storage System (4 Levels)
类型:qbank
A CodeSignal four-level OA modeling an in-memory cloud storage system: add/copy/get files, prefix/suffix search, per-user capacity limits, and file compression/decompression.
Requirements
Implement an in-memory cloud storage system mapping files to metadata (name, size). Four progressive levels; any solution passing the unit tests is accepted.
Level 1 — Core file ops (signatures as given in the prompt):
bool AddFile(const std::string& name, int size);
// Adds file `name` of `size` bytes. Fails (returns false) if a file with that name already exists.
bool CopyFile(const std::string& name_from, const std::string& name_to);
// Copies name_from -> name_to. Fails if name_from doesn't exist or is a directory,
// or if name_to already exists.
std::optional<int> GetFileSize(const std::string& name);
// Returns the file's size, or nullopt if it doesn't exist.
Level 2 — Search. Find files by matching prefixes and suffixes.
Level 3 — Users & capacity. Add users each with their own capacity limit; account file sizes against the owning user's quota.
Level 4 — Compression. Support compressing and decompressing files.
It is guaranteed queries never create collisions between file and directory names.
Examples
AddFile("/dir1/dir2/file.txt", 10) -> true; adds file of 10 bytes
CopyFile("/not-existing.file", "/dir1/file.txt") -> false; source does not exist
CopyFile("/dir1/dir2/file.txt", "/dir1/file.txt") -> true
AddFile("/dir1/file.txt", 15) -> false; file already exists
CopyFile("/dir1/file.txt", "/dir1/dir2/file.txt") -> false; destination exists
GetFileSize("/dir1/file.txt") -> 10
GetFileSize("/not-existing.file") -> nullopt
Execution time limit 30s; memory limit 4g.
Notes
The signatures above are shown in C++ in the prompt, but the framework lets you implement in your language of choice; keep the same return semantics (false/nullopt on failure).
Treat names as path-like strings; Level 2's prefix/suffix search and Level 3's per-user quota both read cleanly if Level 1 stores (name -> size, owner) rather than just (name -> size).
Preparation
Implement Levels 1–2 (add/copy/get + prefix/suffix search) and test the failure paths (duplicate add, copy of a missing/dir source, copy onto an existing name).
Add per-user capacity accounting and a compress/decompress pair, keeping ownership and compressed-size bookkeeping consistent.