FastPrepThird Largest Element in One Pass
Problems/Third Largest Element in One Pass

Third Largest Element in One Pass

PeopleStrong logoPeopleStrong● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PeopleStrong onsite interview. The candidate was asked for the third largest element with one loop, O(n) time and O(1) space. The report does not say how to handle repeated values. This exercise counts every occurrence. We chose the limits. Our version is about 90% the same as the reported question.

Given an integer array nums with at least three elements, return the third largest element when the elements are ordered from largest to smallest.

For this exercise, assume equal values occupy separate positions. For example, the third largest element of [5,5,5,2] is 5. The required final solution uses one pass through the array and constant extra space.

Function

thirdLargest(nums: int[]) → int

Examples

Example 1

nums = [7,2,9,4,1]return = 4

The descending order starts 9,7,4, so the third element is 4.

Example 2

nums = [5,5,5,2]return = 5

All three copies of 5 occupy a ranking position.

Constraints

  • For this exercise, assume 3 <= nums.length <= 100000.
  • -10^9 <= nums[i] <= 10^9.
  • Duplicate occurrences count separately toward the rank.

More PeopleStrong Onsite Interview questions

  • Add Two Binary StringsONSITE INTERVIEW · Seen Mar 2026
  • Four SumONSITE INTERVIEW · Seen Mar 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Mar 2026
  • Sliding Window MaximumONSITE INTERVIEW · Seen Mar 2026
  • Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Sep 2025
  • Integer to English Words: Up to 20 DigitsONSITE INTERVIEW · Seen Sep 2025
  • Word Ladder II: All Shortest TransformationsONSITE INTERVIEW · Seen Sep 2025
  • Detect a Cycle in a Linked ListONSITE INTERVIEW · Seen May 2025
  • First Nonrepeating CharacterONSITE INTERVIEW · Seen May 2025
  • Longest Subarray with a Target SumONSITE INTERVIEW · Seen May 2025

Similar questions at other companies

  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Sort Products by Aisle With Frozen Items LastInstacart · ONSITE INTERVIEWInstacart interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Sort Documents Left to RightFigma · ONSITE INTERVIEWFigma interview questions

Interview reports that mention this question

  • PeopleStrong SDE OA and Interview Questions: 12 Experiences
All PeopleStrong interview questionsSee PeopleStrong hiring insights
Saved
class Solution {
    public int thirdLargest(int[] nums) {
        // Write your solution here.
    }
}
Checking account…