Cloud Storage System
AirbnbOnline assessmentHard
You are building an in-memory cloud storage system as the class CloudStorage. A file has a unique name and a size.
Part 1: File operations
Implement:
add_file(name, size)adds a file and returnstrue, or returnsfalsewithout changing anything when a file with that name already exists.get_file_size(name)returns the file's size, ornullwhen there is no such file.delete_file(name)removes the file and returns the size it had, or returnsnullwhen there is no such file.
- Example 1
- init
[]- operations
[["add_file",["a.txt",10]],["add_file",["b.txt",5]],["add_file",["a.txt",99]],["get_file_size",["a.txt"]],["get_file_size",["zzz"]],["delete_file",["a.txt"]],["delete_file",["a.txt"]],["get_file_size",["a.txt"]],["add_file",["a.txt",7]],["get_file_size",["a.txt"]]]- Output
[true,true,false,10,null,10,null,null,true,7]
Why: The second add of
a.txtfails because the name exists. Reading a missing file givesnull. Deletinga.txtreturns its size 10; deleting it again givesnull, and the name can be added again with a new size.
Constraints
0 <= size <= 10^91 <= len(name) <= 100, and a name uses ASCII letters, digits and. / _ -- At most
10^4calls in total
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.