

Gary has recently learned about priority queues and is quite excited about them. He has asked his teacher for an interesting problem. So, his teacher came up with a simple problem.
The problem is that he now has an integer array 'ARR'. For every index i, he wants to find the product of the largest, second largest and the third largest integer in the range [0, i] given that array has 0 based indexing.
You have to return the list as required.
Note: Two numbers can be the same value-wise but they should be distinct index-wise.
Example:If the array is [2, 3, 3, 4], the answer should be:-
-1
-1
18 (3 * 3 * 2)
36 (4 * 3 * 3)
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains an integer N, representing the number of elements in the array.
The second line contains N single space-separated integers X[0],X[1],X[2].... X[N-1] where X[i] is an element of the array.
Output format:
For each test case, return the required list. If there is no second largest or third largest number in the array X up to that index then print "-1", without the quotes.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^5
1 <= X[i] <= 10^6
Time limit: 1 sec
1
4
2 3 1 4
-1 -1 6 24
-1 (no second largest as well as third largest element is present)
-1 (no third largest element is present)
6 (3 * 2 * 1)
24 (4 * 3 * 2)
1
6
1 5 7 3 9 12
1 -1 35 105 315 756
It is very clear from the question that it is a priority queue question. All we need to do is work on the first largest, second largest and third largest elements which makes it clear that the max priority queue will come to play.
O(N * log N), where N is the size of the array.
In the worst case, we will be inserting all N elements in the priority queue O(N) and for each element, we will require only the top 3 elements from the priority queue (N * 3logN). Thus the overall time complexity will be O(N * logN).
O(N), where N is the size of the array.
In the worst case, we are using a priority queue to store N elements.