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.

Be the first one to answer
Select
Add answer anonymously...

Top Full Stack Developer Interview Questions Asked at Virtusa Consulting Services

Q. Given an array of integers, sort the array in ascending order.
Q. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
Q. Can you describe the use case of Account Statements Transcription as a full stac...read more
Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits