Tuesday, 7 March 2017

Geeksforgeeks Solution For " Second Largest "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Given an array, return second  largest element from an array.

Submit Your Solution :- Click Here 


Solution :-

#include <iostream>
#include<algorithm>
#include <vector>
using namespace std;
int main() 
{   
    int t,i,j;
cin>>t;
while(t--)
{
   int n,sum=0;
   cin>>n;
   vector <int> arr(n);
   for(i=0;i<n;i++)
   {
    cin>>arr[i];
}
   sort(arr.begin(),arr.end());
   for(i=n-2;i>=n-2;i--)
   {
       cout<<arr[i]<<endl;
   }     
}
return 0;
}

Output:-

Geeksforgeeks Solution For " Second Largest "

No comments:
Write comments

Recommended Posts × +