Uber · Question 64 · Dynamic Programming
Longest Increasing Subsequence (LIS)
Problem
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Approach
Greedy + Binary Search: Maintain a tails array where each element represents the minimum tail for subsequences of that length.
Time O(nlogn)Space O(n)
How it works
- 1Maintain tails: smallest tail per subsequence length.
- 2Binary-search each number's position; extend or replace.
- 3tails length is the LIS length.
Sample input / output
Input: 8 10 9 2 5 3 7 101 18 Output: 4
Constraints
1 <= nums.length <= 2500; -10^4 <= nums[i] <= 10^4.
Solution — read it, then walk it
Time O(nlogn)Space O(n)Loops 1Branches 3Returns 1source · Python
Scroll sideways for wide charts — the view follows the active step.
- start / end
- statement
- condition
- loop
- returns
- definition
1/20
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits