FastPrepSecond Largest Element in an Array
Problems/Second Largest Element in an Array

Second Largest Element in an Array

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a new grad candidate in a 2022 Bank of America campus drive for a Senior Tech Associate role, in a 20 to 30 minute technical interview over a video call that followed the online test. The coding task, done in Java, was to return an array's second largest value. The candidate's first solution ran in O(N) time without extra space; asked for a different way, they described one built on a hash map and a list.

The report does not give examples or limits, or say how repeated values count. Here, a repeated value counts once, so the answer is the largest value below the maximum, and the array has 2 to 10,000 integers with at least two different values.

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

Find the second largest value in an integer array nums, that is, the biggest number in it that is strictly less than the maximum, and return it.

A value counts once no matter how many times it appears, so no copy of the maximum can be the answer. nums always holds at least two different values, so an answer exists.

Function

secondLargest(nums: int[]) → int

Examples

Example 1

nums = [41,-7,88,63,88,12]return = 63

The maximum is 88, and it appears twice. Neither copy can be the answer. The other values are 41, -7, 63, 12, and the biggest of them is 63.

Example 2

nums = [-15,-40]return = -40

The maximum is -15. The only value below it is -40, so that is the answer.

Example 3

nums = [5,9,9,9,5]return = 5

The maximum 9 appears three times, and 5 appears twice. The only value below 9 is 5, so the answer is 5.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • nums contains at least two different values.

More Bank of America Onsite Interview questions

  • Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
  • Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
  • N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
  • Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
  • Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
  • Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
  • Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
  • Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023

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

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights
Saved
class Solution {
    public int secondLargest(int[] nums) {
        // write your code here
    }
}
Checking account…