← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Apr 2026

Summary

Google SWE coding round, one problem the whole time: Russian Doll Envelopes. Felt manageable if you've drilled LIS before, but there's a subtle sorting trick that will absolutely sink you if you haven't seen it.

Questions Asked (1)

Q1

Given a list of envelopes as (width, height) pairs, find the longest chain where each envelope strictly fits inside the next one.

Algorithms & Data Structures
Author's notes

The core problem is LeetCode 354.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then propose a dynamic programming solution that sorts envelopes by width ascending and height descending, followed by finding the longest increasing subsequence (LIS) on heights. Optimize the LIS step using binary search to achieve O(n log n) time complexity.

Pro tip: Mention that sorting height in descending order for equal widths prevents invalid chains where two envelopes have the same width. Also, discuss how this problem is a variation of the classic Russian Doll Envelopes problem, showing pattern recognition.

1. Clarify the problem

Ask about input size, whether envelopes can be rotated, and if dimensions are integers. Confirm that both width and height must be strictly smaller.

2. Sort envelopes

Sort by width ascending; for equal widths, sort by height descending. This ensures that when we process envelopes, we only consider strictly increasing heights for valid chains.

3. Reduce to LIS

Extract the heights in sorted order and find the longest strictly increasing subsequence. This gives the maximum chain length.

4. Optimize LIS

Use binary search (patience sorting) to compute LIS in O(n log n) time, explaining that a naive DP would be O(n^2).

5. Analyze complexity

State that sorting takes O(n log n) and LIS takes O(n log n), so overall O(n log n) time and O(n) space.

Key Points to Mention

  • Dynamic programming approach for LIS
  • Sorting with custom comparator (width asc, height desc)
  • Binary search optimization for LIS (patience sorting)
  • Time and space complexity analysis
  • Edge cases: empty list, single envelope, duplicate dimensions
  • Comparison to similar problems like Russian Doll Envelopes

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