FastPrepNth-Highest Distinct Salary Without Ranking Functions

Nth-Highest Distinct Salary Without Ranking Functions

Mastercard logoMastercard● MediumFULLTIMEONSITE INTERVIEW

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

ColumnTypeNullableDescription
employee_idPKIntegerNo—
employee_nameTextNo—
salaryDecimalNo—

query_params

Contains exactly one row with param_id 1.

ColumnTypeNullableDescription
param_idPKIntegerNo—
nIntegerNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
salaryDecimalNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • query_params contains exactly one row with param_id = 1 and positive n.
  • Duplicate salary values occupy one position.
  • Return no rows when fewer than N distinct salaries exist.

More Mastercard problems

See Mastercard hiring insights