FastPrepMedian Blocks per Page in Each Database
Problems/Median Blocks per Page in Each Database

Median Blocks per Page in Each Database

Notion logoNotion● MediumFULLTIMEPHONE SCREEN

Updated May 2024

QuestionConstraints

Problem statement

Source note: Reported in a Notion BI engineer coding interview. The round asked for SQL over data that comes from the Notion API. The candidate was also asked how to find a median in SQL and when to pick an average over a median.

The report does not give the tables or the exact queries. Here, we chose three tables shaped like Notion databases, pages and blocks, and the task of finding each database's median block count per page. Pages with no blocks count as 0, and archived pages are skipped. With an even number of pages, the median is the average of the two middle counts. A database with no pages left is not listed. The average-or-median question is the follow-up and is answered in the solution, not tested.

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

For each Notion database, return the median number of blocks per page, counting only pages that are not archived.

The tables hold data exported from the Notion API. notion_databases has one row per database. notion_pages has one row per page, with the database it belongs to and whether it is archived (moved to the trash). notion_blocks has one row per block, which is one piece of content on a page such as a paragraph, heading or to-do item.

  • The block count of a page is the number of rows in notion_blocks with its page_id. A page with no blocks has a count of 0.
  • Skip archived pages. Their blocks do not count anywhere.
  • The median is the middle value of a database's sorted block counts. When the database has an even number of pages, the median is the average of the two middle values.
  • Leave out a database with no pages that are not archived. If no database is left, return an empty table with the three columns.

Return the columns database_id, title and median_block_count, in this order. Return the rows in any order. median_block_count is accepted when it is within 0.0001 of the exact value.

Follow-up: When is the average block count a better summary than the median, and when is the median better?

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.

notion_databases

One row per Notion database.

ColumnTypeNullableDescription
database_idPKIntegerNoUnique database ID.
titleTextNoDatabase title.

notion_pages

One row per page. Every page belongs to one database.

ColumnTypeNullableDescription
page_idPKIntegerNoUnique page ID.
parent_database_idIntegerNoThe database the page belongs to.
archivedBooleanNoTrue when the page was moved to the trash.

Foreign key: parent_database_id → notion_databases(database_id)

notion_blocks

One row per block of content on a page.

ColumnTypeNullableDescription
block_idPKIntegerNoUnique block ID.
page_idIntegerNoThe page the block is on, even when it is nested inside another block.
block_typeTextNoBlock type, for example 'paragraph' or 'to_do'.

Foreign key: page_id → notion_pages(page_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
database_idIntegerNo—
titleTextNo—
median_block_countDecimalNo—

Row order: any order is accepted. Numeric tolerance: 0.0001.

Constraints

  • notion_databases has between 1 and 100 rows.
  • notion_pages has between 1 and 1000 rows.
  • notion_blocks has between 0 and 2000 rows.
  • database_id, page_id and block_id are unique in their tables.
  • Every parent_database_id is a database_id in notion_databases, and every block's page_id is a page_id in notion_pages.
  • title has between 1 and 100 characters.

More Notion Phone Screen questions

  • Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
  • Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
  • Country with the Most EventsPHONE SCREEN · Seen Mar 2026
  • Event Type with the Most EventsPHONE SCREEN · Seen Mar 2026
  • Most Popular Active Plan for the Top Event TypePHONE SCREEN · Seen Mar 2026
  • Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
  • Percentage of Blocks Never EditedPHONE SCREEN · Seen Mar 2026
  • Versioned Document StorePHONE SCREEN · Seen Apr 2025

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
  • 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
  • Nth-Highest Book Sales VolumeAmazon · PHONE SCREEN

Interview reports that mention this question

  • Notion interviews · 2024

Notion interview experiences

  • Notion interviews · Before 2022
  • Notion interviews · 2022
  • Notion interviews · 2023
  • Notion interviews · 2025
  • Notion interviews · 2026
All Notion interview questionsSee Notion hiring insights