Second Distinct Largest Element
Updated
Problem statement
Given an integer array nums containing at least two distinct values, return its second-largest distinct value.
Repeated occurrences of the largest value do not count as a separate value.
Function
secondLargestDistinct(nums: int[]) → intExamples
Example 1
nums = [5,1,5,3]return = 3Example 2
nums = [2,2,1]return = 1Source note: Author-written prompt excerpt retained for source fidelity.
More HSBC interview questions
- Maximum 69 NumberONSITE INTERVIEW · Seen Oct 2026
- Organization Reputation After Employee DeparturesOA · Seen Nov 2026
- Remove Vowels from a StringOA · Seen Nov 2026
- Minimum Deletion Cost for Distinct Adjacent CharactersOA · Seen Oct 2026
- Distinct Products After Removing One ElementOA · Seen Sep 2026
- Minimum Cleaning Robot RunsOA · Seen Sep 2026
- Minimum Satellite Data Transfer IterationsOA · Seen Aug 2026
- Find ID of SoldierOA · Seen Jun 2026
- Find Most Frequently Purchased ProductsOA · Seen Jun 2026
- Minimum Markers to Clear Line SegmentsOA · Seen Nov 2025
Similar questions at other companies
- Bad Request AlertsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Confusing Bib NumbersVerily · ONSITE INTERVIEW
- 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