Loading problem...
You are given an integer array nums representing a sequence of values. Your task is to determine the length of the longest strictly ascending chain that can be formed by selecting elements from the array while preserving their relative order.
A strictly ascending chain (also known as a subsequence) is a selection of elements where:
In other words, you need to find the maximum number of elements you can pick from the array such that each picked element is larger than the previous one you picked, and the selected elements appear in the same order as in the original array.
Key Distinction: This is different from finding a contiguous increasing subarray. You can skip elements as long as the relative order is preserved and each selected element is strictly larger than the previous selected element.
nums = [10,9,2,5,3,7,101,18]4One possible longest ascending chain is [2, 3, 7, 101]. The elements maintain their relative order: 2 appears before 3, which appears before 7, which appears before 101 in the original array. Each subsequent element is strictly greater than the previous one. Another valid chain of length 4 is [2, 3, 7, 18]. The length of this longest chain is 4.
nums = [0,1,0,3,2,3]4A longest ascending chain is [0, 1, 2, 3]. Note that elements can be chosen from different positions: 0 (index 0), 1 (index 1), 2 (index 4), 3 (index 5). Another valid chain is [0, 1, 3] with indices [0, 1, 3 or 5], but it only has length 3. The maximum achievable length is 4.
nums = [7,7,7,7,7,7,7]1Since all elements are identical (7), no element is strictly greater than another. Therefore, the longest strictly ascending chain contains only a single element. Any single element forms a valid chain of length 1, but no chain of length 2 or more is possible because the chain must be strictly increasing.
Constraints