The input format says there will only be 1 integer n followed by n integers but there is also one other input being given
Question not clear
I/p
1st line T : no of test cases
2nd line: n , k : size of input array , k top elements to be printed
3rd line: n array elements
O/P
for each element i in 1:n:
print top k elements keeping in mind if no. of elements read till now are less than k then print ’ i ’ elements
eg :
5 2
5 1 3 5 2
for 5 since only 1 element is read, top 1 elemnt is printed to console
for 5,1 acc to q it has to be o/p in increasing order & acc to increasing frequency so 1 5 is printed
similary 1 3 (k = 2)(taking top 2 from increasing order of 1 3 5 )
for 5 1 3 5 ( freq{5,2} freq{1,1} freq{3,1} ) so since 5 has highest frequency so 5 is printed first then other element with same freq in increasing order upto k elements.
Hope this provides clarity.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.