Practice/Netflix/Versioned File System
CodingMust
Design and implement an in-memory file management system with versioning support. The system should support basic CRUD operations (Create, Read, Update, Delete) and maintain version history for crash recovery.
This problem has similarities to LeetCode 1146 (Snapshot Array) and tests your understanding of versioning systems like Git.
You'll build this incrementally across multiple parts, with increasing complexity and production considerations.
Implement a FileSystem class with the following methods:
create(path, content) - Create a new fileread(path) - Read file contentupdate(path, content) - Update existing filedelete(path) - Delete a file` fs = FileSystem()
fs.create("/documents/report.txt", "Q1 Report") # True fs.create("/documents/report.txt", "Duplicate") # False (already exists)
print(fs.read("/documents/report.txt")) # "Q1 Report" print(fs.read("/nonexistent.txt")) # None
fs.update("/documents/report.txt", "Q1 Report - Updated") # True print(fs.read("/documents/report.txt")) # "Q1 Report - Updated"
fs.delete("/documents/report.txt") # True print(fs.read("/documents/report.txt")) # None `
True for successful create/update/delete, False if operation failsNone when reading non-existent filesExtend the FileSystem class with versioning capabilities:
snapshot() - Take a snapshot of the current state, returns snapshot IDread_at_version(path, snap_id) - Read file content at a specific snapshotThe user should be able to take a "snapshot" and later retrieve the file content at any previous snapshot.
` fs = FileSystem()
fs.create("/config.txt", "v1") snap0 = fs.snapshot() # Returns 0
fs.update("/config.txt", "v2") snap1 = fs.snapshot() # Returns 1
fs.update("/config.txt", "v3")
print(fs.read("/config.txt")) # "v3"
print(fs.read_at_version("/config.txt", 0)) # "v1" print(fs.read_at_version("/config.txt", 1)) # "v2" `
None at snapshots after deletionNone