int increasingSubsequenceLength(int[] values) {
int[] tails = new int[values.length];
int size = 0;
for (int value : values) {
int i = lowerBound(tails, size, value);
tails[i] = value;
if (i == size) size++;
}
return size;
}
def increasing_subsequence_length(values: list[int]) -> int:
tails = []
for value in values:
i = lower_bound(tails, value)
if i == len(tails):
tails.append(value)
else:
tails[i] = value
return len(tails)
def increasingSubsequenceLength(values: Array[Int]): Int =
val tails = Array.fill(values.length)(0)
var size = 0
for value <- values do
val i = lowerBound(tails, size, value)
tails(i) = value
if i == size then size += 1
size
int increasingSubsequenceLength(const std::vector<int>& values) {
std::vector<int> tails;
for (int value : values) {
auto it = std::lower_bound(tails.begin(), tails.end(), value);
if (it == tails.end()) tails.push_back(value);
else *it = value;
}
return tails.size();
}