
Remove an element from the start of the array.
Remove an element from the end of the array.
2 * min > max
Where 'min' is the minimum element of the array, and 'max' is the maximum element of the array, calculated each time for the updated array.
The first line contains an integer 'T', denoting the number of tests.
For each Test :
The first line contains an integer 'N', denoting the length of the array 'A'.
The second line contains an array 'A' of length 'N'.
For each test, print an integer, denoting the minimum number of operations required such that the given condition holds true.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= 'T' <= 5
1 <= 'N' <= 10^5
1 <= A[i] < 10^9 i ∈ (1,N)
Time Limit: 1 sec
In each recursion call, find the minimum and maximum elements in the array, and if condition (2*min > max) holds, return 0, denoting that 0 removals are needed for range [L, R]. Otherwise, the answer for this call will be [1 + minimum among recursion(L+1, R) and recursion(L, R-1)].
Algorithm:
This thing can be optimized using dynamic programming. A dp of size N*N is made where dp[i][j] contains the same result as recursion(i, j), but no pair (i, j) will be calculated more than once.
Algorithm:
Run two nested loops to fix the starting and ending points of subarrays and keep track of the minimum and maximum values. Among all the subarrays which satisfy the given condition, consider the length of the longest subarray. Let the longest length be ‘len’, our answer becomes [N - len].
Algorithm: