INPUT : ARR [ ] = [ 1 , 2 , 3 , 4 , 5 ] , N = 4
OUTPUT: ARR [ ] = [ 1 , 2 , 4, 5 ]
The above example contains an odd number of elements, hence the middle element is clearly the (N+1) / 2th element, which is removed from the stack in the output.
INPUT : ARR [ ] = [ 5, 6, 7, 8 ] , N = 3
OUTPUT: ARR [ ] = [ 5, 7, 8 ]
The above example contains an even number of elements, so out of the two middle elements, we consider the one which occurs first. Hence, the middle element would be ((N+1) / 2 - 1) element, which is 6 and is removed from the stack in the output.
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first line of each test case contains an integer 'N', where 'N+1' denotes the number of elements in the stack initially.
The second line of each test case contains 'N+1' space-separated integers, denoting the elements of the stack.
For every test case, print 'N' space-separated integer, denoting the elements in the stack after removing the middle element from the input stack.
The output of every test case will be printed in a separate line.
You donβt have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N+1 <= 3000
0 <= data <= 10^9
Where βTβ is the number of test cases, βN+1β is the number of elements in the input Stack. βdataβ is the value of each element in the stack.
Time limit: 1 second
The idea is to use recursive calls. We first remove all items one by one, then we recur. After recursive calls, we push all items back except for the middle item.
Algorithm:
Algorithm :
Mario And His Princess
Stock Span
Hills and Soldier
Hills and Soldier
Hills and Soldier
Next Greater Element II
8-Queen Problem