← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Meta SWE interview with a mix of classic and slightly-off-the-beaten-path coding problems. The 2D rectangle merge variant was the one that stuck with me.

Questions Asked (4)

Q1

Find the kth largest element in an unsorted array.

Algorithms & Data Structures
Author's notes

Went with a min-heap of size k.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., array size, value range, duplicates) and then present multiple solutions with trade-offs. Begin with a simple sorting approach, then optimize using a min-heap of size k or Quickselect for average O(n) time. Discuss the choice based on expected input and system constraints.

Pro tip: Mention that Quickselect has O(n) average but O(n^2) worst-case, and you can avoid the worst-case by using a randomized pivot or the Median of Medians algorithm. Also, note that for streaming data or when k is small, a heap is more practical.

1. Clarify requirements and constraints

Ask about input size, value range, whether duplicates count as separate elements, and if the array can be modified. This shows you consider edge cases and practical limits.

2. Propose a baseline solution

Suggest sorting the array and returning the element at index n-k. This is simple and O(n log n) time, O(1) extra space if in-place, but may be inefficient for large n.

3. Optimize with a heap

Explain using a min-heap of size k: iterate through the array, push elements, and if heap size exceeds k, pop the smallest. At the end, the heap root is the kth largest. This is O(n log k) time and O(k) space, good for large n and small k.

4. Present Quickselect for average O(n)

Describe the Quickselect algorithm: partition the array around a pivot, then recursively search the side that contains the kth largest. Average O(n) time, worst-case O(n^2), but can be mitigated with random pivots.

5. Compare trade-offs and choose

Discuss when to use each approach: sorting for simplicity, heap for streaming or small k, Quickselect for optimal average time when the array can be modified. Mention that Quickselect modifies the array, which may not be allowed.

Key Points to Mention

  • Time and space complexity of each approach (sorting: O(n log n), heap: O(n log k), Quickselect: O(n) average, O(n^2) worst-case).
  • Handling duplicates: clarify if kth largest means kth distinct element or kth in sorted order including duplicates.
  • Edge cases: k=1 (maximum), k=n (minimum), empty array, k out of bounds.
  • Stability and whether the original array can be modified (Quickselect modifies it).
  • Randomized pivot selection to avoid worst-case in Quickselect.
  • Alternative: using a max-heap of size n and extracting k times, but that's O(n + k log n) which is worse than min-heap for small k.

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

Q2

Group strings that belong to the same shift sequence (i.e., strings that can be transformed into each other by shifting each character by the same amount).

Algorithms & Data Structures
Author's notes

Took me a minute to nail down the key normalization.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that two strings are in the same shift sequence if the differences between consecutive characters (mod 26) are identical. Then propose a solution that computes a canonical key for each string, such as the tuple of cyclic differences, and groups strings using a hash map. Discuss time and space complexity, and consider edge cases like different lengths and empty strings.

Pro tip: Mention that the difference array can be normalized by taking modulo 26 to handle negative differences, and that using a tuple as a hash key in Python is efficient. Also, note that strings of different lengths cannot be in the same group, so you can skip them early.

1. Clarify the problem

Confirm that shifting means adding the same integer k to each character (mod 26), and that strings must be of equal length to be in the same group. Ask if the shift amount can be any integer.

2. Define a canonical key

For a string s, compute the sequence of differences d_i = (s[i+1] - s[i]) mod 26 for i from 0 to n-2. This sequence uniquely identifies the shift equivalence class.

3. Group using a hash map

Iterate through the list of strings, compute the key for each, and use a dictionary to map each key to a list of strings. Skip strings of different lengths or handle them separately.

4. Analyze complexity and edge cases

Time complexity is O(N * L) where N is number of strings and L is average length. Space is O(N * L) for storing keys. Discuss empty strings, single-character strings, and strings with different lengths.

5. Test and optimize

Walk through a small example to verify correctness. Consider if the key can be further optimized (e.g., using a string representation of differences) and discuss trade-offs.

Key Points to Mention

  • Shift equivalence is determined by the pattern of differences between consecutive characters modulo 26.
  • Use a hash map with the difference tuple as the key to group strings efficiently.
  • Strings of different lengths cannot be in the same group, so they can be filtered out early.
  • Time complexity: O(N * L) where N is number of strings and L is average length; space complexity: O(N * L).
  • Edge cases: empty strings, single-character strings, and strings with all identical characters.
  • Alternative approach: normalize each string by shifting the first character to 'a' and compare the resulting strings.

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

Q3

Given a set of 2D rectangles, merge all overlapping ones into the smallest set of non-overlapping rectangles. This is a 2D extension of the classic merge intervals problem.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This was the rough one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and defining what 'overlapping' means (e.g., intersection area > 0). Then, discuss a sweep-line algorithm that processes events sorted by x-coordinate, maintaining active rectangles and merging them along the y-axis. Finally, analyze the time and space complexity and consider trade-offs with simpler but less efficient approaches.

Pro tip: Mention that the problem is non-trivial because merging rectangles can create new overlaps, so a naive pairwise merge may not yield the minimal set. Emphasize the importance of handling edge cases like touching edges or containment.

1. Clarify requirements and constraints

Ask about input size, whether rectangles are axis-aligned, if overlapping includes touching edges, and if the output must be minimal or just non-overlapping.

2. Define overlap and merge conditions

Specify that two rectangles overlap if their projections on both axes overlap. Merging them results in the bounding box of the union.

3. Propose a sweep-line algorithm

Sort events (left and right edges) by x-coordinate. Maintain a set of active rectangles and merge intervals along the y-axis at each x-interval.

4. Handle merging and output

When active rectangles change, compute the merged y-intervals and emit rectangles for the previous x-interval. Ensure no overlapping output rectangles.

5. Analyze complexity and trade-offs

Discuss O(n log n + k) time where k is the number of output rectangles, and O(n) space. Compare with simpler O(n^2) pairwise merge that may not be minimal.

Key Points to Mention

  • Sweep-line algorithm with events sorted by x-coordinate
  • Active set of rectangles and interval merging on y-axis
  • Handling of edge cases: touching edges, containment, zero-area overlaps
  • Time complexity: O(n log n + k) where k is output size
  • Space complexity: O(n) for active set and events
  • Trade-offs: minimal set vs. simple non-overlapping set, and potential use of interval trees

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

Q4

Given a binary search tree and a range [low, high], return the sum of all node values within that range.

Algorithms & Data Structures
Author's notes

Pretty clean problem to end on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the BST property to prune branches: if the current node's value is less than low, skip the left subtree; if greater than high, skip the right subtree. Otherwise, include the node's value and recursively process both subtrees. This yields an efficient O(n) worst-case but often O(log n + k) time where k is the number of nodes in range.

Pro tip: Mention that you can further optimize by stopping recursion when the node's value is out of range, and discuss how this pruning makes the solution efficient for large trees. Also, clarify that the sum can be computed using any traversal (in-order, pre-order) but pruning is key.

1. Clarify the problem

Confirm that the tree is a BST, the range is inclusive, and node values are integers. Ask if the tree can be empty or if low > high.

2. Choose traversal strategy

Decide on a recursive DFS approach that leverages BST ordering to prune subtrees that cannot contain values in range.

3. Define recursive function

Write a function that takes a node and returns the sum. If node is null, return 0. If node.val < low, recurse only on right; if node.val > high, recurse only on left; else include node.val and recurse both sides.

4. Analyze complexity

Explain that time complexity is O(n) worst-case but typically O(log n + k) where k is nodes in range, and space is O(h) for recursion stack.

5. Test with examples

Walk through a simple BST and range to verify correctness, including edge cases like empty tree or range outside all values.

Key Points to Mention

  • BST property: left subtree values < node < right subtree values
  • Pruning: skip left if node.val < low, skip right if node.val > high
  • Inclusive range: include nodes where low <= val <= high
  • Recursive DFS with pruning
  • Time complexity: O(n) worst-case, but often O(log n + k) with k nodes in range
  • Space complexity: O(h) for recursion stack, h is tree height

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