PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving skills, particularly reasoning about multi-dimensional ordering, sequence optimization, and time-complexity analysis.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Find Maximum Envelope Nesting

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a list of envelopes, where each envelope is represented by `[width, height]`. One envelope can be placed inside another only if both its width and height are strictly smaller than the other envelope's. Envelopes cannot be rotated. Return the maximum number of envelopes that can be nested. Example: - Input: `[[5,4],[6,4],[6,7],[2,3]]` - Output: `3` - Explanation: One valid nesting chain is `[2,3] -> [5,4] -> [6,7]`. Assume the input size can be large enough that an efficient solution is required.

Quick Answer: This question evaluates algorithmic problem-solving skills, particularly reasoning about multi-dimensional ordering, sequence optimization, and time-complexity analysis.

You are given a list of envelopes, where each envelope is represented by [width, height]. One envelope can be placed inside another only if both its width and height are strictly smaller than the other envelope's. Envelopes cannot be rotated. Return the maximum number of envelopes that can be nested. For example, given [[5,4],[6,4],[6,7],[2,3]], the answer is 3 because one valid chain is [2,3] -> [5,4] -> [6,7]. The input can be large, so an efficient solution is required.

Constraints

  • 0 <= len(envelopes) <= 100000
  • 1 <= width, height <= 1000000000
  • Envelopes cannot be rotated
  • Envelope A can fit into envelope B only if A.width < B.width and A.height < B.height

Examples

Input: [[5, 4], [6, 4], [6, 7], [2, 3]]

Expected Output: 3

Explanation: A valid nesting is [2,3] -> [5,4] -> [6,7], so the maximum count is 3.

Input: []

Expected Output: 0

Explanation: With no envelopes, no nesting is possible.

Input: [[1, 1]]

Expected Output: 1

Explanation: A single envelope can form a nesting chain of length 1 by itself.

Input: [[4, 5], [4, 6], [6, 7], [2, 3], [1, 1]]

Expected Output: 4

Explanation: One optimal chain is [1,1] -> [2,3] -> [4,5] -> [6,7]. Envelopes [4,5] and [4,6] cannot nest because their widths are equal.

Input: [[2, 2], [2, 3], [2, 4]]

Expected Output: 1

Explanation: All envelopes have the same width, so none can fit into another. The maximum chain length is 1.

Input: [[5, 4], [6, 4], [6, 7], [2, 3], [7, 8], [7, 8]]

Expected Output: 4

Explanation: A longest valid chain is [2,3] -> [5,4] -> [6,7] -> [7,8]. The duplicate [7,8] does not increase the answer.

Hints

  1. If you sort by width in ascending order, be careful with envelopes that have the same width.
  2. After sorting correctly, the problem can be reduced to finding the length of a longest increasing subsequence on heights.
Last updated: May 6, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
  • Streaming Points: Remove Any Pair Within a Distance - Google (medium)
  • Boolean Expression Tree with Leaf Flips - Google (medium)
  • Most Active Users in a Live Communication Stream - Google (medium)
  • Solve Rooms and Top-K Streams - Google (medium)