Longest Increasing Subsequence
Updated
Problem statement
Given an integer array nums, return the length of its longest strictly increasing subsequence.
A subsequence is formed by deleting zero or more elements without changing the relative order of the remaining elements.
Function
lengthOfLIS(nums: int[]) → intExamples
Example 1
nums = [10,9,2,5,3,7,101,18]return = 4One longest strictly increasing subsequence is [2, 3, 7, 101], which has length 4.
Example 2
nums = [0,1,0,3,2,3]return = 4The subsequence [0, 1, 2, 3] is strictly increasing and has the maximum possible length.
Example 3
nums = [7,7,7,7,7,7,7]return = 1Equal values cannot both appear in a strictly increasing subsequence, so the maximum length is 1.
Constraints
1 <= nums.length <= 2500-10^4 <= nums[i] <= 10^4
More Amazon Onsite Interview questions
- Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Removals for a Nice ArrayAdobe · ONSITE INTERVIEWAdobe interview questions
- Longest Increasing SubsequenceMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Increasing SubsequenceExpedia · ONSITE INTERVIEWExpedia interview questions
- Minimum Cost for TicketsRoku · ONSITE INTERVIEWRoku interview questions
- Longest Increasing SubsequencePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions