Skip to content

Commit eb80ecd

Browse files
Number of Students Doing Homework at a Given Time
Difficulty: Easy 111 / 111 test cases passed. Runtime: 36 ms Memory Usage: 13.7 MB
1 parent 9c29273 commit eb80ecd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Given two integer arrays startTime and endTime and given an integer
3+
queryTime.
4+
The ith student started doing their homework at the time startTime[i] and
5+
finished it at time endTime[i].
6+
Return the number of students doing their homework at time queryTime.
7+
More formally, return the number of students where queryTime lays in the
8+
interval [startTime[i], endTime[i]] inclusive.
9+
10+
Example:
11+
Input: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4
12+
Output: 1
13+
Explanation: We have 3 students where:
14+
- The first student started doing homework at time 1 and
15+
finished at time 3 and wasn't doing anything at time 4.
16+
- The second student started doing homework at time 2 and
17+
finished at time 2 and also wasn't doing anything at time 4.
18+
- The third student started doing homework at time 3 and
19+
finished at time 7 and was the only student doing homework at
20+
time 4.
21+
22+
Constraints:
23+
- startTime.length == endTime.length
24+
- 1 <= startTime.length <= 100
25+
- 1 <= startTime[i] <= endTime[i] <= 1000
26+
- 1 <= queryTime <= 1000
27+
"""
28+
#Difficulty: Easy
29+
#111 / 111 test cases passed.
30+
#Runtime: 36 ms
31+
#Memory Usage: 13.7 MB
32+
33+
#Runtime: 36 ms, faster than 87.04% of Python3 online submissions for Number of Students Doing Homework at a Given Time.
34+
#Memory Usage: 13.7 MB, less than 100.00% of Python3 online submissions for Number of Students Doing Homework at a Given Time.
35+
36+
class Solution:
37+
def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:
38+
number_of_students = 0
39+
for i, start_time in enumerate(startTime):
40+
if queryTime in range(start_time, endTime[i]+1):
41+
number_of_students += 1
42+
return number_of_students

0 commit comments

Comments
 (0)