FastPrepSecond Distinct Largest Element

Second Distinct Largest Element

HSBC logoHSBC● EasyNEW GRADONSITE INTERVIEW
Learn

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[]) → int

Examples

Example 1

nums = [5,1,5,3]return = 3

Example 2

nums = [2,2,1]return = 1

Source note: Author-written prompt excerpt retained for source fidelity.

More HSBC problems

See HSBC hiring insights
public int secondLargestDistinct(int[] nums) {
  // write your code here
}
nums[5,1,5,3]
expected3
Checking account…