Fourth Largest Element in the Array
Given an array consisting of integers, your task is to determine the fourth largest element in the array. If the array does not contain at least four distinct elements, return the minimum possible value of an integer, which is -2147483648.
Input:
The first line of input contains the integer 'N', which indicates the number of elements in the array.
The second line contains N space-separated integers that represent the elements of the array.
Output:
Output the fourth largest integer if it exists, otherwise output -2147483648.
Example:
Input:
6
2 3 1 5 6 4
Output:
3
Explanation:
The fourth largest element in the sorted array [1, 2, 3, 4, 5, 6] is 3.
Constraints:
- 1 <= N < 106
- -106 <= element <= 106
- Time Limit: 1 sec
Note:
There is no need to explicitly print the output; the function should be implemented to return the answer.
Be the first one to answer
Add answer anonymously...
Top Maersk Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Maersk Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app