Problem Description
Given two arrays, startTime and endTime, which represent when students start and finish their homework respectively, and an integer queryTime, determine how many students are doing homework at queryTime. A student is considered to be doing homework at queryTime if queryTime lies in the interval [startTime[i], endTime[i]].
Key Insights
- The problem requires iterating through each student's start and end times.
- For each student, check if queryTime is within their homework time interval.
- A simple count is maintained as we check each student.
- Given the constraints, a linear scan is both efficient and sufficient.
Space and Time Complexity
Time Complexity: O(n), where n is the number of students. Space Complexity: O(1), as we only use a counter and no additional data structures.
Solution
Iterate through the arrays startTime and endTime simultaneously. For each student, check if the queryTime lies between the start and end times (inclusive). If it does, increment a counter. Finally, return the counter. This approach uses a basic loop with a conditional check, making it straightforward and efficient for the given constraints.