Microsoft: Teams Meetings That Ran Past Their Booked Slot

Easy
774.

Microsoft: Teams Meetings That Ran Past Their Booked Slot

EasyDates

MySQL

A Microsoft Teams product analyst studying meeting overload wants to know which meetings ran longer than the slot their organiser booked.

For every meeting that has ended and lasted strictly longer than booked_minutes, return meeting_id, organizer and overrun_minutes — the minutes between started_at and ended_at, minus the booked minutes. Meetings still in progress have ended_at NULL and are left out. Order by overrun_minutes descending, then meeting_id ascending.

A practice scenario set at Microsoft: the tables and data are invented, and this is not a question from, or endorsed by, Microsoft.

Tables

Table: TeamsMeeting

ColumnType
meeting_idint
organizervarchar
booked_minutesint
started_atdatetime
ended_atdatetime

Primary key: meeting_id.

One row per scheduled meeting. Times are whole minutes; a meeting can run past midnight. ended_at is NULL while the meeting is still going.

Example

The rows must come back in the order shown.

TeamsMeeting

meeting_idorganizerbooked_minutesstarted_atended_at
1Priya302025-04-01 10:00:002025-04-01 10:42:00
2Rahul602025-04-01 11:00:002025-04-01 12:00:00
3Zara302025-04-01 14:00:00NULL
4Arjun452025-04-02 09:05:002025-04-02 09:41:00
5Meera152025-04-02 16:00:002025-04-02 16:27:00
6Kabir602025-04-02 17:30:002025-04-02 18:45:00
7Diya302025-04-03 23:50:002025-04-04 00:25:00

Output

meeting_idorganizeroverrun_minutes
6Kabir15
1Priya12
5Meera12
7Diya5
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

Microsoft: Teams Meetings That Ran Past Their Booked Slot

A Microsoft Teams product analyst studying meeting overload wants to know which meetings ran longer than the slot their organiser booked.

  • Difficulty: Easy
  • Topics: Dates
  • Dialect: MySQL
  • Problem: #774

Problem statement

A Microsoft Teams product analyst studying meeting overload wants to know which meetings ran longer than the slot their organiser booked.

For every meeting that has ended and lasted strictly longer than booked_minutes, return meeting_id, organizer and overrun_minutes — the minutes between started_at and ended_at, minus the booked minutes. Meetings still in progress have ended_at NULL and are left out. Order by overrun_minutes descending, then meeting_id ascending.

A practice scenario set at Microsoft: the tables and data are invented, and this is not a question from, or endorsed by, Microsoft.

Tables

Table: TeamsMeeting

ColumnType
meeting_idint
organizervarchar
booked_minutesint
started_atdatetime
ended_atdatetime

Primary key: meeting_id.

One row per scheduled meeting. Times are whole minutes; a meeting can run past midnight. ended_at is NULL while the meeting is still going.

Examples

Example 1

TeamsMeeting

meeting_idorganizerbooked_minutesstarted_atended_at
1Priya302025-04-01 10:00:002025-04-01 10:42:00
2Rahul602025-04-01 11:00:002025-04-01 12:00:00
3Zara302025-04-01 14:00:00NULL
4Arjun452025-04-02 09:05:002025-04-02 09:41:00
5Meera152025-04-02 16:00:002025-04-02 16:27:00
6Kabir602025-04-02 17:30:002025-04-02 18:45:00
7Diya302025-04-03 23:50:002025-04-04 00:25:00

Output

meeting_idorganizeroverrun_minutes
6Kabir15
1Priya12
5Meera12
7Diya5

How to solve Microsoft: Teams Meetings That Ran Past Their Booked Slot

The actual length of a meeting is TIMESTAMPDIFF(MINUTE, started_at, ended_at); the overrun is that minus booked_minutes. Because the difference is computed on full timestamps, a meeting from 23:50 to 00:25 is 35 minutes long, not negative — working with the clock time alone would break there.

The filter keeps overruns that are strictly positive: a meeting that ended exactly on time is not news. Meetings still running have ended_at NULL; the explicit IS NOT NULL documents that, and even without it the difference would be NULL and the comparison would drop the row.

The alternative computes the overrun once in a derived table and filters on overrun_minutes > 0, which relies on that NULL behaviour. Either way it is one scan; the final sort puts the worst offenders first and breaks ties by id so the order is fixed.

Reference solution (MySQL)

SELECT meeting_id, organizer,
       TIMESTAMPDIFF(MINUTE, started_at, ended_at) - booked_minutes AS overrun_minutes
FROM TeamsMeeting
WHERE ended_at IS NOT NULL
  AND TIMESTAMPDIFF(MINUTE, started_at, ended_at) > booked_minutes
ORDER BY overrun_minutes DESC, meeting_id

Another way

SELECT meeting_id, organizer, overrun_minutes FROM (
  SELECT meeting_id, organizer, TIMESTAMPDIFF(MINUTE, started_at, ended_at) - booked_minutes AS overrun_minutes FROM TeamsMeeting
) t WHERE overrun_minutes > 0 ORDER BY overrun_minutes DESC, meeting_id ASC

← Microsoft: Dev and Test VMs Still Billing Over the Weekend · Microsoft: Licensed Users With No Successful Sign-In →