Second Largest Number in Array

E · easyP · Verified PYQarrays

Find the second largest distinct element in an array of N integers.

2 <= N <= 10\*\*5
Input
5
4 2 9 1 9
Output
4
Use two variables: largest and second_largest. Traverse once. Handle duplicate largest values.
← Rotate Array Right by 1 PositionSelection Sort →
Report an issue with this question