July 2021

A - Hulk Likes It His Way

Solution

\[\]

Implementation

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    
    while(t--)
    {
        int n, i;
        cin>>n;
        
        int a[n];
        for(i = 0; i < n; i++)
            cin>>a[i];
            
        /*
            Sorting the array and reversing the same array will
            sort the array in decreasing order
        */
        sort(a, a+n);
        reverse(a, a+n);
        
        //Print the second element of the array
        cout<<a[1]<<"\n";
    }
}
\[\]

Contest Material