
‘ARR’ = {3, 5, 1, 4}
In this example, the total number of elements greater than or equal to 3 are 3, 4, 5.
Hence the value of ‘K’ is 3.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the total number of elements in the array.
The next line contains ‘N’ integers denoting the elements of the array.
For each test case, print a single integer ‘K’ denoting the maximum possible value such that the total number of elements that are greater than or equal to ‘K’ is at least ‘K’.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 5000
1 <= ‘ARR’[i] <= 10^5
Time limit: 1 sec
In this approach, We will iterate through all the elements and check if for the current index we have elements greater than or equal to the current index.
The steps are as follows:
In this approach, We will iterate through all the elements and store the count of all the elements in a vector and iterate through the vector till the ‘totalCount’ is greater than or equal to the current value.
The steps are as follows: