跟地理面经有点不一样的file storage 前两问差不多,创建file,创建user 第三问adjust capacity,减少user的capacity的时候要考虑删除最大size的files。 第四问的是compress和decompress file。
有一点就是level 2里的sorted in lexicographical order of the names 需要格外注意下,用priorityqueue 的时候需要另外处理string。 其余就是,只要实现,不考虑任何性能优化,所以按照最简单最直接的方法写,这样后面比较容易debug
Your task is to implement a simple cloud storage system, All operatlons that should be supported are listed below.
Requirements Your task is to implement a simple cloud storage system that maps objects (files) to their meta information. Specifically, the storage should maintain files and information about them (name, size, etc.). Note that this system should be In-memory: you don't need to work with the real filesystem.
Level 1: The cloud storage system should support adding a new flie and retrieving and deleting files. Level 2: The cloud storage system should support displaying the largest files. Level 3: The cloud storage system should support adding users with limited capacities and merging two users Level 4: The cloud storage system should support backing up restoring a user's files
Level 1 The cloud storage system should support file manipulation. add file(self, name: str, size: int) -> bool -should add a new file name to the storage. size is the amount of memory required in bytes. The current operation fails if a file with the same name already exists. Retums True if the file was added successfully or False otherwise
get_file_size(self,d 's files are deleted. If a file can't be restored because another user added another file with the same name, it ls ignored. Returns the number of the files that are successfully restored or None if user id does not exist.
Note that merge user does not affect user id 1 's backup, and user id 2 is deleted along with its backup Note that the restore_user operation does not affect the user's capacity
总体的问题和这篇帖子差不太多,但是level 2以后的细节不太一样
level2 要求按prefix 和suffix 找到user的files,再按一定顺序排序 level3 要动态改user的capacity,如果新的capacity 不够存的话就要按一些rules 删掉原来的文件 level4 要做compress 和 decompress,大概就是size 减半/double
Some Tips: prefix scan 不需要用到trie, 直接每个name和prefix对比就好 Top N 不需要用到 ordered set/ priority queue,直接sort 然后取前N个就好 你可以点开test case 的file来看你fail的test case的具体内容,这样很方便debug
|