FastPrepNth-Highest Book Sales Volume
Problems/Nth-Highest Book Sales Volume

Nth-Highest Book Sales Volume

Amazon logoAmazon● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionConstraints

Problem statement

Source note: In an Amazon intern SQL phone screen built around book sales, the candidate was asked for the highest sales figure, then the Nth highest, and then for the Nth highest again with no LIMIT and no nested query. The interviewer wanted a function there, which points to a window function.

The report does not give the table or what to return when there is no Nth value. Here, N comes from a one-row query_params table, equal sales volumes count once, and you return no rows when there are fewer than N distinct values. We check only the result, not whether you used LIMIT or a subquery.

Our version is about 80% the same as the reported question.

The book_sales table has one row per book: a unique book_id, the book's title, and its sales_volume, the number of copies sold. The query_params table has exactly one row, and its n column holds a positive integer N.

Return the Nth-highest distinct sales_volume. Books with the same sales volume share one position. For example, if the sales volumes are 700, 700 and 400, the 2nd-highest distinct value is 400.

Return one column named sales_volume with one row. If there are fewer than N distinct sales volumes, return no rows.

Interview follow-up

The interview built up to this question in steps:

  1. Find the highest sales volume.
  2. Find the Nth-highest sales volume.
  3. Find it again without LIMIT and without nested queries. The interviewer wanted a function here, which means a window function.

Try to answer with a window function. The judge checks only the result rows.

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.

book_sales

One row per book.

ColumnTypeNullableDescription
book_idPKIntegerNo—
titleTextNo—
sales_volumeIntegerNo—

query_params

Exactly one row, with param_id 1.

ColumnTypeNullableDescription
param_idPKIntegerNo—
nIntegerNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
sales_volumeIntegerNo—

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

Constraints

  • The book_sales table has from 0 to 10^5 rows.
  • book_id is unique, and 1 <= book_id <= 10^9.
  • title has 1 to 100 characters. Two books can have the same title.
  • 0 <= sales_volume <= 10^9.
  • query_params has exactly one row, with param_id = 1 and 1 <= n <= 10^5.
  • No column is NULL.

More Amazon Phone Screen questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
  • Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026
  • Count the 1 Bits in a 32-Bit ValuePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Nth Highest SalaryPaytm · PHONE SCREENPaytm interview questions
  • Email Funnel: Opened Within a Day, Replied Within a WeekSuperhuman · PHONE SCREENSuperhuman interview questions
  • iPhone Model Sales Share by CountryApple · PHONE SCREENApple interview questions
  • Top Three Accounts by Monthly Transaction AmountMastercard · PHONE SCREENMastercard interview questions
  • In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Top Three Sales per County and YearClickhouse · PHONE SCREEN
  • Block Type with the Most ChildrenNotion · PHONE SCREENNotion interview questions
  • Third-Highest Known SalaryAdobe · PHONE SCREENAdobe interview questions
  • Days Between Each User's Latest Two PostsZip · PHONE SCREENZip interview questions
  • Observed-User Percentage by AppMicrosoft · PHONE SCREENMicrosoft interview questions

Interview reports that mention this question

  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights