777. Longest Increasing Subsequence (Recursive + Memoization)

MediumRecursionRecursion

Given an integer array nums, return the LENGTH of the longest STRICTLY increasing subsequence. A subsequence is a sequence derived by deleting some (possibly zero) elements without changing the relative order. If nums is empty, return 0. Implement with recursion + memoization.

Input: An integer array nums.

Output: Return an integer — the longest strictly increasing subsequence length.

Examples

Example 1
Input: [10,9,2,5,3,7,101,18]
Output: 4
Explanation: One LIS is [2,3,7,101] with length 4.
Example 2
Input: [7,7,7,7]
Output: 1
Explanation: All equal, strict increase requires length 1.
Example 3
Input: [0,1,0,3,2,3]
Output: 4
Explanation: One LIS is [0,1,2,3].

Constraints

Asked by

MicrosoftAmazonGoogleInfosysBloombergAccenture
Solve this problem in the editor →