Russian Doll Envelopes
Updated
Problem statement
You are given a two-dimensional integer array envelopes, where envelopes[i] = [width_i, height_i] describes one envelope.
One envelope can fit inside another only when both its width and its height are strictly smaller than the other envelope's dimensions. Envelopes cannot be rotated.
Return the maximum number of envelopes that can be nested inside one another.
Function
maxEnvelopes(envelopes: int[][]) → intExamples
Example 1
envelopes = [[5,4],[6,4],[6,7],[2,3]]return = 3One maximum nesting chain is [2,3] -> [5,4] -> [6,7], which contains 3 envelopes.
Example 2
envelopes = [[1,1],[1,1],[1,1]]return = 1Equal dimensions are not strictly smaller, so no two envelopes can be nested.
Constraints
1 <= envelopes.length <= 10^5envelopes[i].length == 21 <= width_i, height_i <= 10^5
More InMobi Onsite Interview questions
- Minimum and Maximum with Optimal ComparisonsONSITE INTERVIEW · Seen Dec 2025
- Minimum Edges to Connect All ComponentsONSITE INTERVIEW · Seen Dec 2025
- Shortest Path Visiting All NodesONSITE INTERVIEW · Seen Sep 2025
- Maximum Sum of Non-Adjacent Tree NodesONSITE INTERVIEW · Seen Jan 2022
- Word SquaresONSITE INTERVIEW · Seen Jan 2022
- Maximum Length Pair ChainONSITE INTERVIEW · Seen Jul 2021
- Top View of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
- Maximum XOR Between Two ArraysONSITE INTERVIEW · Seen May 2021
- Trapping Rain WaterONSITE INTERVIEW · Seen May 2021
- Validate Binary Search TreeONSITE INTERVIEW · Seen May 2021
Similar questions at other companies
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Profit in Job SchedulingAmazon · PHONE SCREEN
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
- Count Later Lower ReadingsRippling · ONSITE INTERVIEWRippling interview questions
- Minimum Total Waiting Time for One ElevatorExpedia · ONSITE INTERVIEWExpedia interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Minimum Removals for a Nice ArrayAdobe · ONSITE INTERVIEWAdobe interview questions