MEDIUMasked at 3 companies

Nth Highest Salary

A medium-tier problem at 38% community acceptance, tagged with Database. Reported in interviews at ZS Associates and 2 others.

Founder's read

Nth Highest Salary is a database problem that hits your OA and you'll freeze if you haven't written a SQL window function in months. It's asked at ZS Associates, Capgemini, and Atlassian, and the acceptance rate sits at 38%, meaning most candidates either overthink it or tank on edge cases like duplicate salaries and null checks. The trick isn't complicated once you see it, but blind you'll spend 20 minutes debugging. StealthCoder solves it in seconds if you blank during the assessment, invisible to the proctor.

Companies asking
3
Difficulty
MEDIUM
Acceptance
38%

Companies that ask "Nth Highest Salary"

If this hits your live OA

Nth Highest Salary is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The problem asks you to find the Nth highest salary, which sounds simple until you realize SQL doesn't have a clean 'get Nth unique value' operator. The obvious trap is using LIMIT N without handling duplicates, which fails immediately. You need to use DENSE_RANK() or ROW_NUMBER() to assign ranks, then filter where rank equals N. The real gotcha is null handling: some test cases expect NULL when N is larger than the dataset or when all salaries are null. Many candidates write the window function correctly but forget the WHERE clause or return the wrong data type. The pattern is: rank all salaries, filter to rank N, handle edge cases with COALESCE or CASE statements. If this lands in your live OA and you haven't written SQL in a while, StealthCoder surfaces the working solution instantly, no proctor visibility.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Nth Highest Salary recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Nth Highest Salary interview FAQ

Why does LIMIT N not work for Nth highest salary?+

LIMIT N returns the Nth row, not the Nth unique value. If two employees have the same salary, LIMIT 2 might return one person twice or skip a salary tier entirely. Use DENSE_RANK() to assign ranks to unique salary values, then filter WHERE rank = N.

Is this problem still asked at top companies?+

Yes. ZS Associates, Capgemini, and Atlassian all report asking it. At 38% acceptance, it's clearly filtering candidates who can't write window functions or handle null edge cases under pressure.

What's the difference between RANK(), ROW_NUMBER(), and DENSE_RANK()?+

ROW_NUMBER() assigns unique numbers to every row (1, 2, 3, 4...). RANK() assigns the same rank to ties, then skips numbers (1, 2, 2, 4...). DENSE_RANK() assigns the same rank to ties but doesn't skip (1, 2, 2, 3...). For Nth highest salary, DENSE_RANK() is usually correct because you want the Nth unique salary level.

What happens if N is larger than the number of distinct salaries?+

Most test cases expect NULL as the output. You'll need a query structure that returns NULL when no row matches the rank condition. Use a subquery or CASE statement to handle this explicitly, not by accident.

How does database knowledge relate to backend interviews?+

Window functions and SQL patterns show whether you understand data retrieval under constraints. Companies like Atlassian value candidates who can write efficient queries without defensive code or brute-force loops. Database problems filter for precision and attention to edge cases.

Want the actual problem statement? View "Nth Highest Salary" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.