EasyNo. 1450

Number of Students Doing Homework at a Given Time — LeetCode 1450 Python Solution

Topics
Array
Reading time
2 min

The problem

Given two integer arrays startTime and endTime and given an integer queryTime. The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].

Example

Input
startTime = [1,2,3], endTime = [3,2,7], queryTime = 4
Output
1
Explanation
We have 3 students where:

Python solution

PythonSolution
class Solution:
    def busyStudent(
        self, startTime: List[int], endTime: List[int], queryTime: int
    ) -> int:
        return sum(x <= queryTime <= y for x, y in zip(startTime, endTime))

Complexity

Time
O(n)where n is the number of students
Space · auxiliary
O(1)

Related problems

Related problems
No.ProblemDifficulty
0057Insert IntervalMedium
0228Summary RangesEasy
0485Max Consecutive OnesEasy
0665Non-decreasing ArrayMedium
0674Longest Continuous Increasing SubsequenceEasy
0699Falling SquaresHard

Frequently asked questions

How hard is LeetCode 1450. Number of Students Doing Homework at a Given Time?

LeetCode 1450. Number of Students Doing Homework at a Given Time is rated Easy on LeetCode.

What is the time complexity of LeetCode 1450. Number of Students Doing Homework at a Given Time?

The Python solution on this page runs in O(n), where n is the number of students.

What is the space complexity of LeetCode 1450. Number of Students Doing Homework at a Given Time?

The Python solution on this page uses O(1) auxiliary space.

What topics does LeetCode 1450. Number of Students Doing Homework at a Given Time cover?

LeetCode 1450. Number of Students Doing Homework at a Given Time is tagged Array on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.