1450. Number of Students Doing Homework at a Given Time
EasyView on LeetCode
Time: O(n)
Space: O(1)
Problem Overview
Count students whose start time <= queryTime and end time >= queryTime.
Intuition
Count students whose start time <= queryTime and end time >= queryTime.
Algorithm
- 1For each student i: if startTime[i] <= queryTime && endTime[i] >= queryTime: count++.
Common Pitfalls
- •Simple O(n) scan. Both conditions must hold.
1450.cs
C#
// Approach: Simple range check; count students whose [startTime, endTime] interval includes queryTime.
// Time: O(n) Space: O(1)
public class Solution
{
public int BusyStudent(int[] startTime, int[] endTime, int queryTime)
{
int n = startTime.Length;
int ans = 0;
for (int i = 0; i < n; ++i)
{
if (startTime[i] <= queryTime && queryTime <= endTime[i])
++ans;
}
return ans;
}
}Was this solution helpful?
Related Problems
- 4. Median of Two Sorted Arrays(Hard)
- 11. Container With Most Water(Medium)
- 15. 3Sum(Medium)
- 16. 3Sum Closest(Medium)
- 26. Remove Duplicates from Sorted Array(Easy)
- 27. Remove Element(Easy)