Challenge: Find Second Maximum Value in an Array

Given an array of size n, can you find the second maximum element in the array? Implement your solution in Java and see if your output matches the correct output!

Problem Statement #

In this problem, you have to implement the int findSecondMaximum(int[] arr) method, which will traverse the whole array and return the second largest element present in the array.

Assumption: Array should contain at least two unique elements.

Method Prototype #

int findSecondMaximum(int[] arr)

Output #

Second largest element present in the array.

Sample Input #

arr = {9,2,3,6}

Sample Output #

6

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.