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 ⌘⏎