FastPrepSecond Largest Element
Problems/Second Largest Element

Second Largest Element

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In a 2023 write-up of Expedia's campus hiring for summer interns, this was the second coding task of the first face-to-face interview. The post names it only through a link to a well-known exercise about the second largest value in an array. The author's first idea was a sort. They then switched to a map, and follow-up questions about maps came up.

The post has no statement or limits, and it does not say how repeated values count or what to return when no answer exists. We chose these. Copies of the maximum are skipped, so the answer is the biggest value below the maximum, and -1 means there is none. Sizes are ours too: up to 10^5 values, each from 1 to 10^9. The map questions are not tested.

Our version is about 85% the same as the reported question.

You are given an array arr of positive integers. Return the second largest value in it: the largest value that is strictly smaller than the largest value in the array.

Copies of the largest value do not count. For example, in [10, 5, 10] the answer is 5, not 10.

If no value is smaller than the largest one (for example, when every value is the same), return -1.

Function

secondLargest(arr: int[]) → int

Examples

Example 1

arr = [12,35,1,10,34,1]return = 34

The largest value is 35. The largest value below 35 is 34, so the answer is 34.

Example 2

arr = [10,5,10]return = 5

The largest value is 10, and it appears twice. A second copy of 10 does not count, because the answer must be smaller than the largest value. The answer is 5.

Example 3

arr = [7,7,7]return = -1

Every value is 7, so no value is smaller than the largest one. The answer is -1.

Constraints

  • 1 <= arr.length <= 10^5
  • 1 <= arr[i] <= 10^9

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Plus OneDruva · ONSITE INTERVIEW
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
  • Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions

Interview reports that mention this question

  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int secondLargest(int[] arr) {
        // Write your code here.
    }
}
Checking account…