Learner Level
Implement the method findSecondLargest that returns the second largest distinct integer in an array.
Return the second largest distinct value from the supplied integer array. The array can contain duplicate values, negative values, and values in any order.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizeelements. - The second largest value must be different from the largest value.
- The test data always contains at least two distinct values.
Track the largest and second largest distinct values while scanning the array. When a new largest value is found, move the old largest into the second largest slot.