Challenge 7: Finding the Second Maximum Value in an Array

In this challenge, you are given an array. Find the second maximum element in the array.

Problem statement

Implement a function findSecondMaximum(int arr[], int size), which takes an array arr and its size as input and returns the second maximum element in the array.

Assumption: Array should contain at least two unique elements.

Input

An array of integers and its size is given.

Output

The second maximum element in the array is the output.

Sample input

[9,2,3,6]

Sample output

6

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