Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Second Largest Element

1 topic · 28 Nov 2026
1

Second Largest Element

Problem Solving
Single pass O(n) · C++
int arr[] = {12, 35, 1, 10, 34, 1};
int first = INT_MIN, second = INT_MIN;
for(int x : arr){
    if(x > first){
        second = first;
        first = x;
    } else if(x > second && x != first){
        second = x;
    }
}
cout << second; // 34