Second Largest Value

EasyArraySorting

Description

Given an array of integers nums containing at least two distinct values, return the second largest distinct value.

Examples

Input:nums = [3,1,4,1,5]
Output:4
Explanation:

After the maximum, the next distinct value down the list is 4.

Input:nums = [10,10,9]
Output:9
Explanation:

After the maximum, the next distinct value down the list is 9.

Input:nums = [-1,-2,-3]
Output:-2
Explanation:

After the maximum, the next distinct value down the list is -2.

Constraints

  • 2 ≤ nums.length ≤ 10⁴
  • At least two distinct values exist.

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.