Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Russian Doll Envelopes

Hard

Topics
ArrayBinary SearchDynamic ProgrammingSorting

You are given a list grid of envelopes where grid[i] = [w, h] is the width and height of envelope i. One envelope fits inside another only if both its width and height are strictly greater. Return the maximum number of envelopes you can nest (Russian doll style).

Example 1

Input:  envelopes = [[5,4],[6,4],[6,7],[2,3]]
Output: 3

Example 2

Input:  envelopes = [[1,1],[1,1],[1,1]]
Output: 1

Constraints

  • 1 <= grid.length <= 10^5
  • grid[i].length == 2
  • 1 <= w, h <= 10^5
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access