#K95662. Max Invert Length of Subarray

    ID: 38914 Type: Default 1000ms 256MiB

Max Invert Length of Subarray

Max Invert Length of Subarray

Given an array of integers, determine the maximum length of a contiguous subarray which, when reversed, becomes sorted in increasing order. In other words, find the longest contiguous segment such that if it is inverted, the sequence becomes non-decreasing.

A subarray is a contiguous part of an array. For a subarray of the form \([a_1, a_2, \dots, a_k]\), if it is non-increasing, i.e., if for every index \(i\) (\(2 \le i \le k\)) we have $$a_i \le a_{i-1},$$ then reversing this subarray will result in a sorted order (i.e., increasing order).

Your task is to process multiple test cases. For each test case, you are given an array. Determine the maximum possible length of such a contiguous subarray.

inputFormat

The input begins with a single integer \(t\) (the number of test cases). Each test case consists of two lines:

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

outputFormat

For each test case, output a single line containing one integer: the maximum length of a contiguous subarray that is non-increasing (which, when reversed, becomes sorted in increasing order).

## sample
1
5
4 3 2 1 5
4

</p>