FastPrepLongest Increasing Subsequence Length

Longest Increasing Subsequence Length

Apple logoApple● MediumNEW GRADOA
Learn

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[]) → int

Examples

Example 1

nums = [1,1,3,2,6,4,1,7]return = 4

One length-four increasing subsequence is [1,3,6,7].

Example 2

nums = [5,3,1]return = 1

Only singleton subsequences increase strictly.

Constraints

  • 1 <= nums.length <= 10^5.
  • -10^9 <= nums[i] <= 10^9.

More Apple problems

See Apple hiring insights
public int lengthOfLIS(int[] nums) {
    // Write your solution here.
}
nums[1,1,3,2,6,4,1,7]
expected4
Checking account…