Russian Doll Envelopes
A hard-tier problem at 37% community acceptance, tagged with Array, Binary Search, Dynamic Programming. Reported in interviews at Intuit and 3 others.
Russian Doll Envelopes is a hard problem that looks like a simple nesting question but absolutely hammers you with a two-dimensional sorting trick that most people miss on first read. Google, Intuit, Atlassian, and Sprinklr all ask it. The acceptance rate hovers around 37%, which means three out of four candidates either time out or submit a solution that passes small test cases and fails on the hidden ones. The problem feels like it should be a standard DP problem until you realize naive DP is way too slow and the real pattern involves both sorting and binary search working together. If this one hits your live assessment and you blank on the trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Russian Doll Envelopes"
Russian Doll Envelopes is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trap is thinking you can just sort the envelopes and run a basic longest increasing subsequence check. That fails because after you sort by width, you still have to handle the height dimension correctly, and a greedy or naive DP approach doesn't account for the fact that envelopes with the same width can't nest inside each other. The real solution requires sorting by width ascending, then by height descending (that's the unintuitive part), followed by finding the longest increasing subsequence on heights only. Binary search on the heights array makes it efficient enough to pass. Most candidates either skip the descending height sort and get wrong answers, or they implement it correctly but don't realize binary search speeds up the LIS part. Array, Binary Search, Dynamic Programming, and Sorting all collide in this problem. StealthCoder handles the exact sorting order and binary search integration during the live assessment, so you don't have to hold that specific pattern in your head under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Russian Doll Envelopes recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Russian Doll Envelopes interview FAQ
Why does sorting by descending height after width matter?+
If you sort both ascending, envelopes with the same width can appear multiple times in your LIS calculation, allowing invalid nesting. Descending height ensures that at each width, you can only pick one envelope, which enforces the constraint that envelopes can't have equal dimensions.
Is this still asked at FAANG?+
Yes. Google, Intuit, Atlassian, and Sprinklr explicitly ask it. With a 37% acceptance rate, it's a standard hard-tier question used to separate candidates who know the pattern from those who don't.
Why doesn't plain DP work here?+
O(n^2) DP on both dimensions gets TLE on large test cases. After the sorted trick, you only need LIS on one dimension, and binary search brings that down to O(n log n), which is the speed you need.
How does this relate to Longest Increasing Subsequence?+
Once you sort correctly, the problem reduces to LIS on heights only. The trick is figuring out that the sorting order (width ascending, height descending) transforms a 2D problem into a 1D LIS problem that's fast enough.
What's the most common mistake?+
Sorting both width and height ascending, then running LIS. This produces wrong answers because it allows multiple envelopes of the same width to be selected, violating the nesting constraint. The descending height sort is the non-obvious fix.
Want the actual problem statement? View "Russian Doll Envelopes" on LeetCode →