#include<bits/stdc++.h>
using namespace std;
void getElements(int arr[],int n)
{
if(n==0 || n==1)
cout<<-1<<" "<<-1<<endl; // edge case when only one element is present in array
int small=INT_MAX,second_small=INT_MAX;
int large=INT_MIN,second_large=INT_MIN;
int i;
for(i=0;i<n;i++)
{
small=min(small,arr[i]);
large=max(large,arr[i]);
}
for(i=0;i<n;i++)
{
if(arr[i]<second_small && arr[i]!=small)
second_small=arr[i];
if(arr[i]>second_large && arr[i]!=large)
second_large=arr[i];
}
cout<<"Second smallest is "<<second_small<<endl;
cout<<"Second largest is "<<second_large<<endl;
}
int main()
{
int arr[]={1,2,4,6,7,5};
int n=sizeof(arr)/sizeof(arr[0]);
getElements(arr,n);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBnZXRFbGVtZW50cyhpbnQgYXJyW10saW50IG4pCnsKICAgIGlmKG49PTAgfHwgbj09MSkKICAgICAgICBjb3V0PDwtMTw8IiAiPDwtMTw8ZW5kbDsgIC8vIGVkZ2UgY2FzZSB3aGVuIG9ubHkgb25lIGVsZW1lbnQgaXMgcHJlc2VudCBpbiBhcnJheQogICAgaW50IHNtYWxsPUlOVF9NQVgsc2Vjb25kX3NtYWxsPUlOVF9NQVg7CiAgICBpbnQgbGFyZ2U9SU5UX01JTixzZWNvbmRfbGFyZ2U9SU5UX01JTjsKICAgIGludCBpOwogICAgZm9yKGk9MDtpPG47aSsrKQogICAgewogICAgICAgIHNtYWxsPW1pbihzbWFsbCxhcnJbaV0pOwogICAgICAgIGxhcmdlPW1heChsYXJnZSxhcnJbaV0pOwogICAgfQogICAgZm9yKGk9MDtpPG47aSsrKQogICAgewogICAgICAgIGlmKGFycltpXTxzZWNvbmRfc21hbGwgJiYgYXJyW2ldIT1zbWFsbCkKICAgICAgICAgICAgc2Vjb25kX3NtYWxsPWFycltpXTsKICAgICAgICBpZihhcnJbaV0+c2Vjb25kX2xhcmdlICYmIGFycltpXSE9bGFyZ2UpCiAgICAgICAgICAgIHNlY29uZF9sYXJnZT1hcnJbaV07CiAgICB9CgogICAgY291dDw8IlNlY29uZCBzbWFsbGVzdCBpcyAiPDxzZWNvbmRfc21hbGw8PGVuZGw7CiAgICBjb3V0PDwiU2Vjb25kIGxhcmdlc3QgaXMgIjw8c2Vjb25kX2xhcmdlPDxlbmRsOwp9CmludCBtYWluKCkKewogICAgaW50IGFycltdPXsxLDIsNCw2LDcsNX07CiAgICBpbnQgbj1zaXplb2YoYXJyKS9zaXplb2YoYXJyWzBdKTsKICAgIGdldEVsZW1lbnRzKGFycixuKTsKICAgIHJldHVybiAwOwp9