


The left half of the array must be the smallest possible.
If there is no partition return the size of the array.
You are given, ‘arr’ = [8, 3, 1, 4, 9, 10], this array can be partitioned at index ‘3’ so the left array is [8, 3, 1, 4] and the right array is [9, 10]. Hence the answer is 4.
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the size of the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the array.
For each test case print a single integer representing the number of elements in the left half of the array.
For each test case, print a single integer.
1 <= T <= 10
1 <= N <= 10^6
1 <= arr[i] <= 10^9
Time Limit: 1 sec
In this approach, we can observe that the array will only be valid if the maximum element of the left array is smaller than the minimum element of the right array.
In the given array we have to find the first index i where the largest element from 0 to i is smaller than the smallest element from i + 1 to N - 1. To do this we can create a maxLeft array and minRight array where maxLeft[i] will store the maximum element till i from left and minRight[i] will store the minimum element till i from right.
Algorithm:
In this approach, we use the same idea that the largest element in the left array should be smaller than the smallest element in the right array.
To do this in one iteration we can do as follows
Algorithm: