FastPrepSecond-Highest Distinct Salary

Second-Highest Distinct Salary

EPAM logoEPAM● EasyFULLTIMEPHONE SCREEN
Learn

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

Examples

Example 1

salaries = [50000,70000,70000,60000]return = 60000

The distinct salaries are 70000, 60000, and 50000.

Example 2

salaries = [42000,42000]return = -1

Only one distinct salary exists.

Constraints

  • 1 <= salaries.length <= 100000.
  • 0 <= salaries[i] <= 10^9.

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

More EPAM problems

See EPAM hiring insights
public int secondHighestSalary(int[] salaries) {
    // Write your code here.
}
salaries[50000,70000,70000,60000]
expected60000
Checking account…