Nth-Highest Distinct Salary Without Ranking Functions
Updated
Problem statement
Return the Nth-highest distinct salary without using ranking window functions such as RANK, DENSE_RANK, or ROW_NUMBER.
The desired positive integer N is supplied in query_params.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
employees
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| employee_name | Text | No | — |
| salary | Decimal | No | — |
query_params
Contains exactly one row with param_id 1.
| Column | Type | Nullable | Description |
|---|---|---|---|
| param_idPK | Integer | No | — |
| n | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| salary | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
query_paramscontains exactly one row withparam_id = 1and positiven.- Duplicate salary values occupy one position.
- Return no rows when fewer than N distinct salaries exist.
More Mastercard interview questions
- Top Three Accounts by Monthly Transaction AmountPHONE SCREEN · Seen Sep 2026
- Deduplicate a List While Preserving OrderPHONE SCREEN · Seen Jul 2026
- Employee With the Highest SalaryPHONE SCREEN · Seen Jul 2026
- Group Names by DepartmentPHONE SCREEN · Seen Jul 2026
- Credit and Debit Transaction Counts per UserPHONE SCREEN · Seen Apr 2026
- Users with Three Transactions in Sixty SecondsPHONE SCREEN · Seen Apr 2026
- Container With Most WaterPHONE SCREEN · Seen Oct 2025
- Employees with the Highest and Lowest SalaryPHONE SCREEN · Seen Apr 2025
- Inactive Customers with Prior ActivityPHONE SCREEN · Seen Nov 2024
- Merchant Category Transaction SummaryPHONE SCREEN · Seen Nov 2024
Similar questions at other companies
- Daily USD Totals with Effective-Dated Exchange RatesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Most Recent Order for Each CustomerCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Tenth-Highest Distinct SalaryInfosys · ONSITE INTERVIEWInfosys interview questions
- Fifth Highest Salary In A DepartmentZS · ONSITE INTERVIEWZS interview questions
- In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Order Book Data ValidationJane Street · ONSITE INTERVIEWJane Street interview questions
- Contest Participants with Long Totals and Short QuestionsThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- First Order per Merchant per DateAmazon · ONSITE INTERVIEW
- Block Transaction Count TrendsChainalysis · ONSITE INTERVIEWChainalysis interview questions
- Third-Highest Distinct SalaryExpedia · ONSITE INTERVIEWExpedia interview questions