Find the Third Greatest Element
Given an array 'ARR' of 'N' distinct integers, determine the third largest element in the array.
Input:
The first line contains a single integer 'T' representing the number of test cases. Each test case consists of: A single integer 'N', the number of elements in the array, on a new line. Followed by 'N' space-separated distinct integers that comprise the array 'ARR'.
Output:
For each test case, output the third largest element from the array 'ARR'.
Example:
Input:
T = 2
N = 5
ARR = [7, 4, 9, 1, 3]
N = 4
ARR = [10, 20, 30, 40]
Output:
4
20
Constraints:
1 <= T <= 50
3 <= N <= 104
-105 <= ARR[i] <= 105
Note:
You don’t need to print anything; it has been handled. Implement the provided function to solve the problem.
AnswerBot
2d
Find the third largest element in an array of distinct integers.
Sort the array in descending order and return the element at index 2.
Handle cases where there are less than 3 elements in the array sepa...read more
Help your peers!
Add answer anonymously...
Top Amdocs Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amdocs 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