Implement Task Management and Duplicate Detection
AnthropicSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design an in-memory task management system with concurrency-aware state tracking and implement an efficient file-deduplication routine using hashing.
Part 1: Task Management Service
Implement a TaskManager class to manage tasks for multiple users. Each task has an id, user_id, priority (1-10), and status ('pending', 'completed').
add_task(user_id, priority): Assign a unique ID and store the task. Enforce a per-user quota of 5 active (non-completed) tasks.list_tasks(user_id): Return tasks sorted by priority (descending).get_history(task_id): Return an audit log of status changes for a given task.
Part 2: File Deduplication
You are given a root directory path. Implement a function to find duplicate files based on content. Two files are duplicates if they have identical contents. Assume you have access to a helper function compute_hash(file_path) that returns a string.
Example
# Task Management
tm = TaskManager()
tm.add_task(user_1, 5)
tm.list_tasks(user_1) # Returns list of tasks for user_1 sorted by priority
# Deduplication
# Input: '/root_dir'
# Output: [['/root_dir/a.txt', '/root_dir/sub/b.txt'], ['/root_dir/c.png']]
# Explanation: Files with identical hashes are grouped together.
Constraints
TaskManager: Perform operations in O(log N) or better where N is the number of tasks.Deduplication: Optimize for memory; do not read the entire file into memory if it is large.
Hints
Hint 1
For the TaskManager, use a dictionary mapping user_ids to a min-heap or a sorted list to maintain priority order and active task counts.
Hint 2
For file deduplication, use a hash map (dictionary) where keys are file hashes and values are lists of file paths.
Hint 3
To optimize deduplication for large files, only compute hashes for files that share the same file size, as files with different sizes cannot be duplicates.
Follow-up questions
- How would you make the TaskManager thread-safe in a multi-threaded environment?
- How would you modify the deduplication routine to handle symbolic links without getting stuck in infinite loops?
- If the task history grows very large, how would you optimize storage for `get_history`?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.