Array operations

 Given an array 

consisting of

non-negative integers.

You need to perform the following operation

times:

  • Sort the array
  • in ascending order.
  • Let
  • be the current size of the array . Replace the array by
    • . Note that each time the operation is performed, the size of the array reduces by one.

    Find the remaining element after

    operations.

    Input Format

    • The first line contains an integer
    denoting number of test cases. The
  • test cases then follow.
  • The first line of each test case contains an integer
  • - the size of the array.
  • The second line of each test case contains
  • space-separated integers
    • .

    Output Format

    For each test case, output single line: the remaining element after

    operations.

    Constraints

  • Sum of
  • over all test cases does not exceed
    • .

    Sample Input 1

    2
    4
    29 19 0 3
    1
    777
    

    Sample Output 1

    1
    777
    

    Explanation

    • Test case 1: The operations look like:
      • Operation
    : Sort the array. Now, becomes . Replace the array. Thus,
  • .
  • Operation
  • : Sort the array. Now, becomes . Replace the array. Thus,
  • .
  • Operation
  • : Sort the array. Now, becomes . Replace the array. Thus,
      • .

    Thus, the remaining element after

    operations is

    .

    • Test case 2: Since
    , you don't need to perform any operation. The remaining element after operations is .
    Previous
    Next Post »