← 返回 goldmansachs 的题目列表Design a Workspace Resource Tree
类型:online_judge
Problem: Design a Workspace Resource Tree
Implement a file-system-like ClayWorkspace to manage resources in a workspace. Each resource has:
a unique id
name
type: FILE or FOLDER
parent_id: the id of its parent folder; None means the resource is at the home level
Support the following operations:
class ClayWorkspace:
def __init__(self):
...
def create_resource(self, resource_name: str, resource_type: ResourceType, parent_folder_id: str | None) -> str:
...
def list_resources(self, folder_id: str | None) -> list[str]:
...
def delete_resource(self, resource_id: str) -> bool:
...
def move_resource(self, resource_id: str, new_parent_folder_id: str | None) -> bool:
...
Semantics
create_resource(name, type, parent_folder_id)
Creates a resource under the given folder.
If parent_folder_id is None, create it at the home level.
Only a FOLDER can be used as a parent.
Return the newly generated resource id.
list_resources(folder_id)
Return the direct children ids of the given folder in insertion order.
If folder_id is None, return direct resources at the home level.
delete_resource(resource_id)
Delete the given resource.
If it is a folder, recursively delete all descendants.
Return True on success, or False if the resource does not exist.
move_resource(resource_id, new_parent_folder_id)
Move a resource under another folder.
If new_parent_folder_id is None, move it to the home level.
The target parent must be a folder.
A folder cannot be moved into its own subtree.
Return True on success, or False for invalid operations.
Constraints
Number of resources N <= 10^5
Number of operations Q <= 10^5
resource_name length is at most 100
Duplicate names under the same folder are allowed in this version; resources are identified by unique ids.
Input/Output Format for Testing
The first line contains an integer Q.
Each of the next Q lines is one command:
CREATE name type parentId
LIST folderId
DELETE resourceId
MOVE resourceId newParentId
Where:
type is FILE or FOLDER
parentId / folderId / newParentId is - for the home level
CREATE prints the generated id: r1, r2, ...
LIST prints direct child ids, or EMPTY if there are no children
DELETE / MOVE prints OK on success, or ERROR on failure
Example
Input
8
CREATE docs FOLDER -
CREATE readme FILE r1
CREATE src FOLDER r1
LIST r1
LIST -
DELETE r1
LIST -
LIST r1
Output
r1
r2
r3
r2 r3
r1
OK
EMPTY
ERROR