#1450
Easy Algorithms Number of students doing homework at a given time
Array
75.8% acceptance
Feb 25, 2026
931
157
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].
Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn busy_student(start_time: Vec<i32>, end_time: Vec<i32>, query_time: i32) -> i32 {
start_time.iter().zip(end_time.iter())
.filter(|&(&s, &e)| s <= query_time && query_time <= e)
.count() as i32
}
}