LeetCode 1450: Number of Students Doing Homework at a Given Time Solution
Master LeetCode problem 1450 (Number of Students Doing Homework at a Given Time), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
1450. Number of Students Doing Homework at a Given Time
Problem Explanation
Explanation:
- Iterate through the startTime and endTime arrays simultaneously.
- For each student, check if the queryTime falls within the interval [startTime[i], endTime[i]].
- Increment a counter if the queryTime is within the interval.
- Return the final count as the number of students doing homework at the given queryTime.
Time Complexity: O(n) where n is the number of students
Space Complexity: O(1)
Solution Code
class Solution {
public int busyStudent(int[] startTime, int[] endTime, int queryTime) {
int count = 0;
for (int i = 0; i < startTime.length; i++) {
if (startTime[i] <= queryTime && queryTime <= endTime[i]) {
count++;
}
}
return count;
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1450 (Number of Students Doing Homework at a Given Time)?
This page provides optimized solutions for LeetCode problem 1450 (Number of Students Doing Homework at a Given Time) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 1450 (Number of Students Doing Homework at a Given Time)?
The time complexity for LeetCode 1450 (Number of Students Doing Homework at a Given Time) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1450 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1450 in Java, C++, or Python.