Design File Management System
Instructions
Design an in-memory file management system, built up over three levels:
- Create & read — create files and retrieve them by ID.
- Update — modify a file's name and content.
- Delete — remove files; IDs are never reused.
Each file has a name, text content, and metadata timestamps for when it was created and last modified. Like most real filesystems, names must be unique and are compared case-insensitively ("Report.txt" and "report.txt" conflict).
Interfaces
class FileManager:
def create_file(self, name: str, content: str, timestamp: int) -> str: ...
def get_file(self, file_id: str) -> str: ...
def update_file(self, file_id: str, name: str, content: str, timestamp: int) -> bool: ...
def delete_file(self, file_id: str) -> bool: ...
Level 1: Create & Read
Implement create_file and get_file.
create_file(name, content, timestamp)stores a new file and returns its assigned ID. IDs are formatted"file1","file2", … and assigned sequentially starting from1. The file's creation and modification times are both set totimestamp. If the name conflicts (case-insensitive) with an existing file, nothing is stored and""is returned.get_file(file_id)returns the file as a pipe-delimited string,"<file_id>|<name>|<content>|<created_at>|<modified_at>", or""if the ID does not exist.
fm.create_file("report.txt", "Q1 numbers", 100) # "file1"
fm.create_file("notes.md", "draft", 105) # "file2"
fm.create_file("REPORT.TXT", "other", 110) # "" — name conflict (case-insensitive)
fm.get_file("file1") # "file1|report.txt|Q1 numbers|100|100"
fm.get_file("file9") # ""
Function signature:
class FileManager:
def __init__(self):
pass
def create_file(self, name: str, content: str, timestamp: int) -> str:
pass
def get_file(self, file_id: str) -> str:
pass
Level 2: Update
Add update_file(file_id, name, content, timestamp), which replaces the file's name and content, sets its modification time to timestamp (creation time is unchanged), and returns True. It returns False if:
file_iddoes not exist, ornameconflicts (case-insensitive) with a different stored file.
Renaming a file to its own name — even with different casing — is allowed.
fm.create_file("report.txt", "v1", 100) # "file1"
fm.create_file("notes.md", "draft", 105) # "file2"
fm.update_file("file1", "Report.txt", "v2", 120) # True — own name, new casing
fm.get_file("file1") # "file1|Report.txt|v2|100|120"
fm.update_file("file2", "REPORT.TXT", "x", 125) # False — conflicts with file1
fm.update_file("file9", "misc.txt", "x", 130) # False — no such ID
Function signature:
class FileManager:
def __init__(self):
pass
def create_file(self, name: str, content: str, timestamp: int) -> str:
pass
def get_file(self, file_id: str) -> str:
pass
def update_file(self, file_id: str, name: str, content: str, timestamp: int) -> bool:
pass
Level 3: Delete
Add delete_file(file_id), which removes the file and returns True, or returns False if the ID does not exist. After deletion the name becomes available again, but the ID counter never goes back — deleted IDs are never reused.
fm.create_file("report.txt", "v1", 100) # "file1"
fm.delete_file("file1") # True
fm.delete_file("file1") # False — already gone
fm.create_file("report.txt", "v2", 140) # "file2" — name free again, ID not reused
fm.get_file("file1") # ""
Function signature:
class FileManager:
def __init__(self):
pass
def create_file(self, name: str, content: str, timestamp: int) -> str:
pass
def get_file(self, file_id: str) -> str:
pass
def update_file(self, file_id: str, name: str, content: str, timestamp: int) -> bool:
pass
def delete_file(self, file_id: str) -> bool:
pass
Anthropic Crash Course
Fullset Newest Anthropic Coding/System Design Questions, Optimal Solutions and Explanations.
Step_1 Matched with a FAANG+ Senior Engineer
Step_2 Fullset Anthropic Coding/System Design Questions
Step_3 Solutions + step by step Explanation
