Skip to the code
cf.
+50 XP

#526 Nest Modal Cards

hard

A design system has card sizes sizes[i] = [width, height]. A card can be placed inside another card only if it is strictly narrower and strictly shorter. Cards can't be rotated.

Write deepestNesting(sizes) that returns the largest number of cards you can nest one inside another.

Example 1

Input: sizes = [[4,3],[5,3],[5,8],[1,2]]
Output: 3

[1, 2] inside [4, 3] inside [5, 8].

Example 2

Input: sizes = [[2,2],[2,2]]
Output: 1

Equal cards don't fit inside each other.

Constraints

  • 1 <= sizes.length <= 100000
  • 1 <= width, height <= 100000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).