Meta questions

Cloud File System

MetaMedium

Build an in-memory cloud file system, CloudStorage. Every file has a unique name and a positive integer size.

Part 1: Files

add_file(name, size) stores a file and returns true, or returns false and changes nothing if a file with that name exists. get_file_size(name) returns the size, or null if there is no such file. delete_file(name) removes the file and returns its size, or returns null if there is no such file. A deleted name can be added again.

  1. Example 1
    init
    []
    operations
    [["add_file",["a/x",30]],["add_file",["a/x",5]],["get_file_size",["a/x"]],["get_file_size",["none"]],["delete_file",["a/x"]],["delete_file",["a/x"]],["get_file_size",["a/x"]],["add_file",["a/x",7]],["get_file_size",["a/x"]]]
    Output
    [true,false,30,null,30,null,null,true,7]

    Why: The second add_file for a/x returns false and the size stays 30. delete_file returns 30 once and null the second time. After that the name is free, so adding it with size 7 works.

Constraints

  • 1 <= number of calls <= 10^5
  • 1 <= size <= 10^9, 1 <= len(name) <= 50
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question
Cloud File System: Meta interview question | LoopCoach