Median Blocks per Page in Each Database
Updated
Problem statement
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_blockswith itspage_id. A page with no blocks has a count of0. - 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
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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| database_idPK | Integer | No | Unique database ID. |
| title | Text | No | Database title. |
notion_pages
One row per page. Every page belongs to one database.
| Column | Type | Nullable | Description |
|---|---|---|---|
| page_idPK | Integer | No | Unique page ID. |
| parent_database_id | Integer | No | The database the page belongs to. |
| archived | Boolean | No | True 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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| block_idPK | Integer | No | Unique block ID. |
| page_id | Integer | No | The page the block is on, even when it is nested inside another block. |
| block_type | Text | No | Block 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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| database_id | Integer | No | — |
| title | Text | No | — |
| median_block_count | Decimal | No | — |
Row order: any order is accepted. Numeric tolerance: 0.0001.
Constraints
notion_databaseshas between1and100rows.notion_pageshas between1and1000rows.notion_blockshas between0and2000rows.database_id,page_idandblock_idare unique in their tables.- Every
parent_database_idis adatabase_idinnotion_databases, and every block'spage_idis apage_idinnotion_pages. titlehas between1and100characters.
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