Skip to content

Practice Nth Highest Salary

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#177
LeetCode Problem

Nth Highest Salary

Problem Statement

Tables: Employee(id INT, salary INT). Employee.id is the unique key. Given n, return the nth-highest distinct salary; return null when there are fewer than n distinct salaries. Count different salary values rather than employee rows.

Source: Nth Highest Salary on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Employee table: +----+--------+ | id | salary | +----+--------+ | 1  | 100    | | 2  | 200    | | 3  | 300    | +----+--------+ n = 2
Output
+------------------------+ | getNthHighestSalary(2) | +------------------------+ | 200                    | +------------------------+

# Example 2

Input
Employee table: +----+--------+ | id | salary | +----+--------+ | 1  | 100    | +----+--------+ n = 2
Output
+------------------------+ | getNthHighestSalary(2) | +------------------------+ | null                   | +------------------------+

Related LeetCode Problems

Practice more problems similar to Nth Highest Salary.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.