Second-Highest Distinct Salary
Problem statement
Given an integer array salaries, return the second-highest distinct salary.
Return -1 if fewer than two distinct salaries are present.
Function
secondHighestSalary(salaries: int[]) → intExamples
Example 1
salaries = [50000,70000,70000,60000]return = 60000The distinct salaries are 70000, 60000, and 50000.
Example 2
salaries = [42000,42000]return = -1Only one distinct salary exists.
Constraints
1 <= salaries.length <= 100000.0 <= salaries[i] <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.