Skip to content
Onsite

Peak number of concurrent sessions

HardP3Coding

Table sessions:

ColumnType
idint (primary key)
start_attimestamp
end_attimestamp (after start_at)

Find the peak number of sessions running at the same time. A session that ends exactly when another starts is not running at the same time as it. For an empty table the peak is 0.

Output: one row, column peak.

Schema

CREATE TABLE sessions (
  id int PRIMARY KEY,
  start_at timestamp NOT NULL,
  end_at timestamp NOT NULL CHECK (end_at > start_at)
);

Example 1

Input
sessions: 10:00-12:00, 10:30-11:30, 11:00-13:00
Output
peak: 3
Why
At 11:00 all three are running.

Example 2

Input
sessions: 10:00-11:00, 11:00-12:00
Output
peak: 1

Constraints

  • PostgreSQL dialect.

Hints

PostgreSQL
Run checks the 3 visible tests, Submit all 7.