The Design a File Sharing System interview question requires you to implement a peer-to-peer ID management system. Users join the system and are assigned the smallest available unique ID. Users can also leave, making their ID available for reuse. Additionally, the system tracks which users own which "chunks" of a file, allowing users to request chunk ownership data and "download" chunks from others.
Twitch asks this to evaluate a candidate's ability to manage state and resources. It tests your proficiency with Heap (Priority Queue) interview patterns for ID reuse and Hash Table interview patterns for mapping file chunks to users. It's a great test of clean API design and efficient data organization.
Map<Integer, Set<Integer>> where the key is the user ID and the value is a set of chunks they own.Map<Integer, Set<Integer>> (Chunk ID -> User IDs).request(chunk: 5): System looks up the chunk map and returns [1, 2] if users 1 and 2 have it. User C (ID 1) then "downloads" it and is added to the chunk 5 ownership list.Think of this as a "Service Design" problem. Modularize your logic: have one part handle IDs and another handle data ownership. This makes the code easier to extend, such as if the system later needs to handle multiple different files.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Stock Price Fluctuation | Medium | Solve | |
| Find Median from Data Stream | Hard | Solve | |
| Design A Leaderboard | Medium | Solve | |
| Logger Rate Limiter | Easy | Solve | |
| Design Task Manager | Medium | Solve |