2nd max
class Solution {
int print2largest(int[] arr, int n) {
int largest = Integer.MIN_VALUE;
int secondLargest = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
if (arr[i] > largest) {
secondLargest = largest;
largest = arr[i];
} else if (arr[i] != largest && arr[i] > secondLargest) {
secondLargest = arr[i];
}
}
return (secondLargest == Integer.MIN_VALUE) ? -1 : secondLargest;
}
}