Leetcode Problem 1500. Design a File Sharing System
1500. Design a File Sharing System
Leetcode Solutions
Priority Queue and HashMap Approach
Initialize a priority queue to store available user IDs and a hash map to map user IDs to their owned chunks.
When a user joins, assign them the smallest available ID from the priority queue and update the hash map with their owned chunks.
When a user leaves, add their ID back to the priority queue and remove their entry from the hash map.
When a user requests a chunk, iterate through the hash map to compile a list of users who own the requested chunk. If the list is not empty, add the chunk to the requesting user's owned chunks.