Challenge: Find Second Maximum Value in an Array
Given an array, can you find the second maximum element in the array? Implement your solution in C++ and see if your output matches the correct output.
We'll cover the following
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. If no such element found then return secondmax
variable.
Assumption: Array should contain at least two unique elements.
Input #
An array of integers and its size
Output #
Second maximum element in the array
Sample Input #
[9,2,3,6]
Sample Output #
6
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.