File: number-of-students-doing-homework-at-a-given-time/solution.py

Date: 2026-06-06

Time: 18:22

Purpose

This file implements LeetCode problem #1450, "Number of Students Doing Homework at a Given Time." It's a self-contained solution + test module — one of hundreds in the leetcode-implementations repo, each following the same solution.py + test_solution.py structure (though here both are combined in a single file).

The responsibility is narrow: given parallel arrays of student start/end times, count how many students are actively working at a specific query time.

Key Components

Solution.busyStudent (line 9) — The core method. Takes three arguments:

Returns the count of students where startTime[i] <= queryTime <= endTime[i]. The contract assumes startTime and endTime are the same length (LeetCode guarantees this).

TestBusyStudent (line 22) — Seven test cases covering the standard examples, all-busy, none-busy, and boundary conditions (query exactly at start, exactly at end, just outside both ends).

Patterns

Dependencies

Imports: unittest (stdlib), typing.List (type annotation only — no runtime effect).

Imported by: The "Imported By" list is misleadingly large — those 300+ testsolution.py files likely share a common test runner (runtests.py at the repo root) rather than directly importing this module. The actual dependent is number-of-students-doing-homework-at-a-given-time/test_solution.py.

Flow

1. Caller passes two equal-length lists and a scalar query time.

2. zip pairs the i-th start with the i-th end time.

3. The generator checks each pair against the chained inequality.

4. sum counts the 1s (truthy matches), returning the total.

Single pass, no intermediate data structures.

Invariants

Error Handling

None. Empty inputs produce 0 naturally (sum of an empty generator is 0). Mismatched list lengths would silently truncate to the shorter list via zip behavior — no error raised.

Topics to Explore

Beliefs