Problem · Dynamic Programming
Colorful Increasing Subsequences
Learn this problemProblem statement
Each candle has a height and one of k colors. Count subsequences whose heights are strictly increasing and that contain every color at least once. Return the result modulo 10^9 + 7.
Function
countColorfulSubsequences(heights: int[], colors: int[], k: int) → intExamples
Example 1
heights = [1,3,2,4]colors = [1,2,2,3]k = 3return = 2The two valid subsequences choose height 1, either height 2 or 3, and height 4.
Constraints
2 <= heights.length = colors.length <= 1001 <= k <= 71 <= colors[i] <= k1 <= heights[i] <= 10^9