Fetching algorithms...
Fetching algorithms...
| id | salary |
|---|---|
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
n = 2
| getNthHighestSalary(2) |
|---|
| 200 |
The distinct salaries are 300, 200, 100.
Ordering them in descending order: 300 (1st highest), 200 (2nd highest), 100 (3rd highest).
For n = 2, the 2nd highest distinct salary is 200.
| id | salary |
|---|---|
| 1 | 100 |
n = 2
| getNthHighestSalary(2) |
|---|
| null |
The distinct salary is only 100.
There is only 1 distinct salary available. Since n = 2, which is greater than the number of distinct salaries, the result is null.