Longest Increasing Subsequence
Problem
Given an integer array nums, return the length of the longest strictly increasing subsequence. A subsequence keeps the original relative order but may skip elements. Strictly increasing means each chosen element is larger than the one before it, so equal values cannot both be used.
numsholds up to a few thousand integers.- Each value fits in a normal signed integer range, positive or negative.
Examples
nums = [8, 6, 1, 4, 2, 9, 88, 15]→4. One longest subsequence is1, 4, 9, 88(also1, 2, 9, 15).nums = [2, 5, 2, 9, 4, 9]→3, for example2, 4, 9.nums = [3, 3, 3]→1. Equal values do not count as increasing.
Hints
- For each element, think about the longest increasing subsequence that must end exactly at that element. How does it relate to earlier elements?
- That gives O(n^2). To go faster, ask: among all increasing subsequences of a given length, which one is the most useful to extend later?
- Maintain, for each length
L, the smallest possible tail of an increasing subsequence of lengthL. That list is sorted, so each new element can be placed with binary search.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.