15% off all plans & roadmaps Use code
See plansLeetCode 354 · Solution & editorial
You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.
Russian Doll Envelopes is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Find LIS using DP and binary search optimization. O(n log n) solution.
The reference solution runs in O(n log n) time and O(n) space.
Russian Doll Envelopes has been reported in interviews at Google, Amazon, ByteDance, Uber.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Russian Doll Envelopes is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.