Binary search · Medium
A trend analyzer can ignore noisy measurements but must preserve their order. It needs the greatest number of selected readings that rise strictly from one selected reading to the next. A consecutive rising run is not sufficient.
Return the length of the longest strictly increasing subsequence without reconstructing the chosen values.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
A JSON object { "nums": number[] }.
Fields
- nums is a sequence in observation order; values may repeat or be negative.
Output
Return value
- Return an integer length. Selected indexes increase but need not be adjacent.
- Equal values do not extend the sequence. Empty input returns 0.
Constraints
- At most 100000 values, each an integer in [-1000000000,1000000000].
Examples
Example 1
{
"nums": [
3,
1,
2,
2,
5,
4
]
}Returns
31,2,5 and 1,2,4 both qualify.
Example 2
{
"nums": [
2,
2,
2
]
}Returns
1Equality does not count as growth.
Required complexity
O(n log(n + 1)) time and O(n) extra space