Problem · Array
Longest Increasing Subsequence
Learn this problemProblem 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 Salesforce problems
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026