← Tradedesk Interview Insights
The add and get_file_size parts were pretty quick to knock out.
Start by clarifying requirements and edge cases, then propose a simple hash map-based design that maps file names to sizes, ensuring O(1) operations. Implement the three operations with careful handling of preconditions and return values, and discuss potential extensions like concurrency and scalability.
Pro tip: Demonstrate maturity by proactively discussing trade-offs (e.g., memory vs. disk storage) and mentioning how you would test edge cases like duplicate adds, missing sources, and concurrent access.
Ask questions to confirm assumptions: Are file names unique? Should operations be thread-safe? What is the expected scale? This shows you think before coding.
Propose using a hash map (dictionary) to store file names as keys and sizes as values, enabling O(1) average-case time for add, copy, and get operations.
Write pseudocode or actual code for each operation, handling edge cases: add returns false if key exists; copy checks source exists and destination doesn't; get returns null if key missing.
State that all operations are O(1) time and O(n) space for n files, and discuss potential improvements like using a trie for prefix searches or a database for persistence.
Mention how to handle concurrency (locks, concurrent data structures), persistence (write to disk), and scalability (sharding, distributed storage) if the interviewer probes further.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.