You are given two integer arrays startTime and endTime, and an integer queryTime.
The i-th student started doing their homework at the time startTime[i] and finished it at endTime[i].
Return the number of students doing their homework at queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.
Example 1:
Input: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4
Output: 1
Explanation: One student was doing their homework at the queryTime.
Example 2:
Input: startTime = [4], endTime = [4], queryTime = 4
Output: 1
startTime.length == endTime.length1 <= startTime.length <= 1001 <= startTime[i] <= endTime[i] <= 10001 <= queryTime <= 1000startTime and endTime lists are of the same length?
queryTime guaranteed to fall within the range from 1 to 1000?
queryTime lies between startTime[i] and endTime[i] inclusive.queryTime is within the range [startTime[i], endTime[i]], we increment our count.def busyStudent(startTime, endTime, queryTime):
count = 0
for i in range(len(startTime)):
if startTime[i] <= queryTime <= endTime[i]:
count += 1
return count
n is the length of the startTime list because we are iterating through all students once.startTime is at most 100, this solution is efficient.startTime = [1,2,3]
endTime = [3,2,7]
queryTime = 4
Output: 1
startTime = [4]
endTime = [4]
queryTime = 4
Output: 1
startTime = [1,1,1,1,1]
endTime = [10,10,10,10,10]
queryTime = 5
Output: 5
startTime = [1,2,3,4,5]
endTime = [5,5,5,5,5]
queryTime = 5
Output: 5
startTime = [1,2,3,4,5]
endTime = [5,6,7,8,9]
queryTime = 1
Output: 1
We can now confidently proceed to check the implementation through these test cases and validate its correctness.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?