#C11831. Minimum Removals for Increasing Toys

    ID: 41191 Type: Default 1000ms 256MiB

Minimum Removals for Increasing Toys

Minimum Removals for Increasing Toys

You are given several test cases. In each test case, there are N toys with various heights. Your task is to remove the minimum number of toys such that the remaining toys have strictly increasing heights.

This can be formulated as follows. Given an array of integers H representing the heights of the toys, you must remove toys so that the remaining sequence satisfies:

$$ H_{i} < H_{j} \quad \text{for all } i < j $$

The optimal solution is to find the length of the Longest Increasing Subsequence (LIS) and then compute the number of removals needed as:

$$ removals = N - L \quad \text{where } L \text{ is the length of the LIS}$$

Compute and output this number for each test case.

inputFormat

The first line of input contains an integer T representing the number of test cases.

Each test case consists of two lines:

  1. The first line contains an integer N, the number of toys.
  2. The second line contains N space-separated integers representing the heights of the toys.

outputFormat

For each test case, output a single integer on a new line denoting the minimum number of removals required to obtain a strictly increasing sequence of toy heights.

## sample
5
5
10 5 6 3 8
4
4 2 3 1
1
1
3
3 1 2
4
4 3 2 1
2

2 0 1 3

</p>