Given an array **A[]** of **N** positive integers. The task is to find the maximum of **j - i** subjected to the constraint of **A[i] <= A[j]**.

**Input:**

The first line contains an integer **T**, depicting total number of test cases. Then T test case follows. First line of each test case contains an integer **N** denoting the size of the array. Next line contains N space separated integeres denoting the elements of the array.

**Output:**

Print the maximum difference of the indexes i and j in a separtate line.

**Constraints:**

1 ≤ T ≤ 1000

1 ≤ N ≤ 10^{7}

0 ≤ A[i] ≤ 10^{18}

**Example:**

**Input:**

1

9

34 8 10 3 2 80 30 33 1

**Output:**

6

**Explanation:
Testcase 1: **In the given array A[1] < A[7] satisfying the required condition(A[i] <= A[j]) thus giving the maximum difference of j - i which is 6(7-1).

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

thanuvinu94 | 292 |

the_coder95 | 258 |

ShivayLamba | 256 |

Ashish Kumar Vaishy | 170 |

adityasuman2025 | 144 |

the_coder95 | 1484 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 968 |

samay_kam_hai | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.