← Tradedesk Interview Insights

Tradedesk·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Coding round at Tradedesk with a file search problem that looks straightforward but has a few sorting gotchas worth thinking through carefully.

Questions Asked (1)

Q1

Implement a function called find_file that searches for files matching a given prefix and suffix, then returns them sorted by size descending and name ascending, formatted as 'name(size)'.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The filtering part was fine but I tripped up on the sort.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the requirements first, including what 'file' means (regular files only?), how to handle errors, and whether recursion is needed. Then outline a solution that traverses the directory, filters by prefix and suffix, collects file metadata, sorts by size descending and name ascending, and formats the output. Discuss trade-offs like memory usage and I/O efficiency.

Pro tip: Mention that you would use a stable sort or a custom comparator to ensure correct ordering when sizes are equal, and consider using a generator to avoid loading all file metadata into memory at once.

1. Clarify requirements and edge cases

Ask about the scope (single directory vs recursive), file types (regular files only?), handling of symlinks, permissions, and errors. Confirm the exact sorting and formatting rules.

2. Design the algorithm

Decide on traversal method (e.g., os.walk for recursion), filtering logic (startswith and endswith), and data collection (store name and size). Consider memory and performance implications.

3. Implement the solution

Write code that traverses, filters, collects metadata, sorts using a key that sorts by size descending and name ascending, and formats each entry as 'name(size)'.

4. Test and validate

Test with edge cases: no matches, multiple files with same size, large directories, and permission errors. Ensure sorting and formatting are correct.

5. Discuss trade-offs and optimizations

Talk about time/space complexity, potential optimizations (e.g., using generators, parallel processing), and how the solution scales.

Key Points to Mention

  • Use of os.walk or os.scandir for efficient directory traversal
  • Filtering with str.startswith and str.endswith
  • Sorting with a custom key: (-size, name) to achieve size descending and name ascending
  • Formatting output as 'name(size)' using f-strings or format
  • Handling errors and edge cases (e.g., permission denied, non-regular files)
  • Time and space complexity analysis, and potential memory optimizations

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.