15% off all plans & roadmaps Use code
See plansLeetCode 300 · Solution & editorial
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Longest Increasing Subsequence is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Find LIS using DP and binary search optimization. O(n log n) solution.
The reference solution runs in O(nlogn) time and O(n) space.
Longest Increasing Subsequence has been reported in interviews at Apple, Amazon, Facebook, Bloomberg, Citrix, Google, ByteDance, Twitter.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Longest Increasing Subsequence is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.