← Harvey Interview Insights

Harvey·Backend Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Interviewed for a backend role at Harvey and got two coding problems. Nothing too wild conceptually but both had more edge cases than I expected, and I don't think I handled them as cleanly as I should have.

Questions Asked (2)

Q1

Given a sentence and a list of tags, return only the tags that appear in the sentence as whole-word matches (case-insensitive). Partial matches don't count, so a tag like 'blue' should not match the word 'blueprint'.

Algorithms & Data Structures
Author's notes

The partial-word thing is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: case-insensitivity, whole-word matching, and handling of punctuation and multiple occurrences. Then propose a solution using tokenization or regular expressions with word boundaries, and discuss trade-offs between approaches. Finally, walk through an example and consider edge cases like tags with special characters.

Pro tip: Mention that using regex word boundaries (\b) can be tricky with tags containing non-word characters (e.g., 'c++'), so tokenizing the sentence into words and using a set for lookup is often more robust and efficient for large inputs.

1. Clarify requirements and edge cases

Ask about case sensitivity, punctuation handling, tags with special characters, and whether the sentence can contain multiple occurrences of the same word. Confirm that 'whole-word' means the tag must match a complete word, not a substring.

2. Choose an approach

Decide between tokenization (split sentence into words, normalize case, check membership) or regex with word boundaries. Discuss trade-offs: tokenization is simple and efficient for large tag lists; regex is concise but may fail with special characters.

3. Implement the solution

If tokenizing: split the sentence on non-alphanumeric characters (or whitespace), convert to lowercase, and use a set for O(1) lookups. If using regex: build a pattern like \b(tag1|tag2|...)\b with case-insensitive flag, escaping special characters.

4. Test with examples and edge cases

Walk through a sample sentence and tag list, verifying that partial matches are excluded and case is ignored. Test edge cases: tags with punctuation, multiple spaces, and empty inputs.

5. Analyze complexity and optimize

State time complexity: O(n + m) for tokenization where n is sentence length and m is number of tags, versus O(n * m) for naive substring checks. Mention space complexity and potential optimizations like using a trie for very large tag sets.

Key Points to Mention

  • Case-insensitive matching: normalize both sentence and tags to lowercase (or use regex case-insensitive flag).
  • Whole-word matching: use word boundaries or tokenization to avoid partial matches like 'blue' in 'blueprint'.
  • Handling punctuation: tokenization should split on non-alphanumeric characters, or regex should account for punctuation as word boundaries.
  • Efficiency: using a set for tag lookup gives O(1) average time per word, making the overall solution O(n + m).
  • Edge cases: tags with special characters (e.g., 'c++'), multiple occurrences, empty sentence or tag list.
  • Trade-offs: regex is concise but may require escaping; tokenization is more explicit and robust for complex tags.

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

Q2

Design and implement an in-memory file system that supports creating directories, listing contents, writing to files, and reading from files.

System DesignData Modeling
Author's notes

I actually liked this one more.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and scope, then model the file system as a tree of nodes with separate directory and file types. Implement core operations (mkdir, ls, write, read) using a map-based structure for O(1) child lookup, and discuss trade-offs like path resolution and concurrency.

Pro tip: Mention that you'd use a trie-like tree with hash maps for children to achieve O(1) lookups, and proactively discuss edge cases like path normalization and concurrent access to show production-level thinking.

1. Clarify Requirements and Scope

Ask about expected operations, path format (absolute vs relative), file size limits, and concurrency needs. Confirm whether persistence or permissions are required.

2. Design Data Model

Define a Node base class with name, type, and metadata; DirectoryNode holds a map of children; FileNode holds content and size. Use a tree structure rooted at '/'.

3. Implement Core Operations

Write methods for mkdir (create directory), ls (list children), write (set file content), and read (get file content). Include path resolution that splits on '/' and traverses the tree.

4. Handle Edge Cases and Errors

Address duplicate names, invalid paths, writing to directories, reading non-existent files, and path normalization (e.g., '..', '.'). Return appropriate errors.

5. Discuss Optimizations and Trade-offs

Talk about time/space complexity, potential concurrency control (locks per node), and alternatives like inode-based designs or using a flat map with full paths.

Key Points to Mention

  • Tree data structure with directory and file nodes
  • Hash map for O(1) child lookup in directories
  • Path resolution and normalization (handling '.', '..', absolute vs relative)
  • Error handling for invalid operations (e.g., mkdir on existing path, read on directory)
  • Concurrency considerations (locks, thread safety) for backend readiness
  • Time and space complexity analysis of each operation

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