Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 673 Number of Longest Increasing Subsequences - Problem Statement

Counting all LIS

This is Number of Longest Increasing Subsequences from LeetCode. Given an array, find how many longest increasing subsequences exist. For [1, 3, 5, 4, 7], the answer is 2 because there are exactly two subsequences of maximum length 4: [1, 3, 5, 7] and [1, 3, 4, 7].

This requires tracking two things: the length AND the count. How do you modify the DP (dynamic programming)? Read the problem statement carefully, noting the constraints.