Year-over-Year Growth

HardSQLSQL

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Table revenue: region TEXT year INTEGER amount INTEGER (one row per region and year; some years are missing for some regions) For each region and year, return the change from the previous calendar year as a whole-number percentage, rounded to the nearest integer. Columns, in this order: region, year, amount, growth percent. Order by region, then year. Growth percent is NULL when the region has no row for the previous calendar year, or when the previous year's amount was 0.

Examples

Input: revenue region | year | amount East | 2023 | 200 East | 2024 | 250 East | 2026 | 300
Output: East | 2023 | 200 | NULL East | 2024 | 250 | 25 East | 2026 | 300 | NULL
There is no 2025 row for East, so 2026 has nothing to compare against.

Constraints

  • Growth can be negative.
  • Integer division would truncate; the answer must be rounded.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More SQL problems