FastPrepRussian Doll Envelopes
Problems/Russian Doll Envelopes

Russian Doll Envelopes

Google logoGoogle● HardINTERNFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Several Google reports name this exercise outright. A firsthand intern report from the 2026 cycle adds that interviewers wanted optimized code with an explanation of its complexity. A later report from an L4 AI/ML loop asks what changes when an envelope may be turned 90 degrees.

None of the reports states limits, so the limits and the examples here are our choice. Turning an envelope breaks our rule that envelopes keep their orientation. So the turning follow-up appears only in the statement and editorial and is not checked.

Our version is about 95% the same as the reported questions.

You are given an array envelopes, where envelopes[i] = [width, height] describes one envelope.

An envelope can be placed inside another only if both its width and its height are strictly smaller. Envelopes may not be rotated.

Return the maximum number of envelopes that can be nested inside one another.

Interview follow-up

Suppose each envelope may be turned 90 degrees before nesting, so [width, height] can also be used as [height, width]. How does the answer change? This follow-up relaxes the no-rotation rule above and is discussed in the editorial; your function still does not allow rotation.

Function

maxEnvelopes(envelopes: int[][]) → int

Examples

Example 1

envelopes = [[4,6],[2,3],[4,8],[3,5],[9,9]]return = 4

The envelopes [2,3], [3,5], [4,6] and [9,9] each fit inside the next, so the answer is 4. [4,8] could take the place of [4,6] but cannot join it, because both are 4 wide and widths must grow.

Example 2

envelopes = [[7,2],[3,9],[5,5]]return = 1

Without turning, no envelope fits inside another. In every pair, one envelope is wider and the other is taller, so the answer is 1. In the rotation follow-up, [7,2] turned into [2,7] would fit inside [3,9] for a chain of 2, but this problem does not allow rotation.

Example 3

envelopes = [[2,2],[2,2],[3,3]]return = 2

The two [2,2] envelopes have the same size, so only one of them can go inside [3,3].

Constraints

  • 1 <= envelopes.length <= 100000.
  • envelopes[i].length == 2.
  • 1 <= envelopes[i][0], envelopes[i][1] <= 100000.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi 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

Interview reports that mention this question

  • Google SWE III ML Experienced Hires: 34 Experiences (Part 1 of 4)
  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int maxEnvelopes(int[][] envelopes) {
        // Write your code here.
    }
}
Checking account…