#K93797. Right Larger Index

    ID: 38499 Type: Default 1000ms 256MiB

Right Larger Index

Right Larger Index

Given an array of integers \(a_0, a_1, \dots, a_{n-1}\), the task is to find, for each element, the index of the first element to its right that is strictly larger than the current element. If there is no such element, output \(-1\) for that position.

Formally, for each index \(i\), you need to determine the smallest index \(j\) (with \(j > i\)) such that \(a_j > a_i\). If no such \(j\) exists, output \(-1\) for that index.

inputFormat

The input begins with an integer \(T\) indicating the number of test cases. Each test case is defined as follows:

  • The first line contains an integer \(n\), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line with \(n\) space-separated integers. The \(i\)-th integer should be the index of the first element to the right of \(a_i\) that is strictly larger than \(a_i\), or \(-1\) if such an element does not exist.

## sample
1
6
2 1 3 4 2 1
2 2 3 -1 -1 -1

</p>