Last Updated: 28 Jun, 2021

4th Highest Element

Easy
Asked in companies
CultfitMicrosoft

Problem statement

Given an array 'ARR' of 'N' integers. Find the fourth highest element present in the give 'ARR'. Return the minimum value of an integer which is -2147483648 if there it does not exists.

Input format:
The first line of input contains the integer 'N' representing the size of the array.

The second line of input contains N space-separated integers representing the array elements.
Output Format:
The only output line contains the fourth-largest element if present, otherwise print -2147483648
Note:
You are not required to explicitly print the output, it has already been taken care of. Just implement the function.
Constraints :
1 <= N < 10^6
-10^6 <= ARR[i] <= 10^6

Where 'ARR[i]' denotes the 'ARR' element at 'ith' position.

Time Limit: 1 sec
Follow Up:
Try solving this problem in O(N) time complexity.