1186. Russian Doll Envelopes

MediumDynamic ProgrammingLIS Family

Given envelopes as [width, height] pairs, 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). The input is JSON {envelopes}.

Input: JSON {envelopes}.

Output: Integer — the maximum number of nested envelopes.

Examples

Example 1
Input: {"envelopes":[[5,4],[6,4],[6,7],[2,3]]}
Output: 3
Explanation: [2,3] -> [5,4] -> [6,7].
Example 2
Input: {"envelopes":[[1,1],[1,1]]}
Output: 1
Explanation: Equal envelopes cannot nest.
Example 3
Input: {"envelopes":[[3,5]]}
Output: 1
Explanation: Single envelope.

Constraints

Asked by

ZomatoGoogleFlipkartAmazonMetaMicrosoft
Solve this problem in the editor →