Longest Increasing Subsequence Length
Updated
Problem statement
Return the length of the longest strictly increasing subsequence in the nonempty integer array nums. A subsequence preserves the original order but may skip elements.
Equal values cannot extend a strictly increasing subsequence. A nonempty decreasing or all-equal array therefore returns 1.
Function
lengthOfLIS(nums: int[]) → intExamples
Example 1
nums = [1,1,3,2,6,4,1,7]return = 4One length-four increasing subsequence is [1,3,6,7].
Example 2
nums = [5,3,1]return = 1The values only go down, so no two of them can be in the same increasing subsequence. The best you can do is a single value.
Constraints
1 <= nums.length <= 10^5.-10^9 <= nums[i] <= 10^9.
More Apple interview questions
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge Two Strings by Maximum Boundary OverlapOA · Seen Sep 2026
- Collect Letters Along a Unique Grid PathOA · Seen Aug 2025
- Maximum Weight in Two BagsOA · Seen Aug 2025
- Ignore SectionsOA · Seen Mar 2024
- Gas Station Circular TourOA · Seen Nov 2021
- House Robber IIOA · Seen Nov 2021
- Clone an Undirected Graph StateOA · Seen Mar 2021
- Maximum Later DifferenceOA · Seen Feb 2021
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Minimum Cost to Attend Required CoursesVisa · OAVisa interview questions
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
- Longest Increasing Subsequence from Two ArraysSquarepoint Capital · OASquarepoint Capital interview questions
- Split Array Largest SumLinkedIn · OALinkedIn interview questions
- Longest Increasing SubsequenceAtlassian · OAAtlassian interview questions
- Maximum Profit from an Increasing Price TripletOdoo · OAOdoo interview questions
- Beautiful RowNutanix · OANutanix interview questions
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions