← Unit 4 · all exercises
Saved in this browser only

The second largest

Return the second largest number in the array. The array always has at least two items, and duplicates count separately — so 5, 5, 3 has a second largest of 5.

int secondLargest(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.secondLargest(new int[]{1, 5, 3}) → 3
  • Solution.secondLargest(new int[]{9, 2}) → 2

There are also 3 hidden tests you can't see. Solve the problem, not the examples.