1450. Number of Students Doing Homework at a Given Time LeetCode Solution

In this guide, you will get 1450. Number of Students Doing Homework at a Given Time LeetCode Solution with the best time and space complexity. The solution to Number of Students Doing Homework at a Given Time problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Number of Students Doing Homework at a Given Time solution in C++
  4. Number of Students Doing Homework at a Given Time solution in Java
  5. Number of Students Doing Homework at a Given Time solution in Python
  6. Additional Resources
1450. Number of Students Doing Homework at a Given Time LeetCode Solution image

Problem Statement of Number of Students Doing Homework at a Given Time

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.

Example 1:

Input: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4
Output: 1
Explanation: We have 3 students where:
The first student started doing homework at time 1 and finished at time 3 and wasn’t doing anything at time 4.
The second student started doing homework at time 2 and finished at time 2 and also wasn’t doing anything at time 4.
The third student started doing homework at time 3 and finished at time 7 and was the only student doing homework at time 4.

See also  2618. Check if Object Instance of Class LeetCode Solution

Example 2:

Input: startTime = [4], endTime = [4], queryTime = 4
Output: 1
Explanation: The only student was doing their homework at the queryTime.

Constraints:

startTime.length == endTime.length
1 <= startTime.length <= 100
1 <= startTime[i] <= endTime[i] <= 1000
1 <= queryTime <= 1000

Complexity Analysis

  • Time Complexity:
  • Space Complexity:

1450. Number of Students Doing Homework at a Given Time LeetCode Solution in C++

class Solution {
 public:
  int busyStudent(vector<int>& startTime, vector<int>& endTime, int queryTime) {
    const int n = startTime.size();
    int ans = 0;

    for (int i = 0; i < n; ++i)
      if (startTime[i] <= queryTime && queryTime <= endTime[i])
        ++ans;

    return ans;
  }
};
/* code provided by PROGIEZ */

1450. Number of Students Doing Homework at a Given Time LeetCode Solution in Java

N/A
// code provided by PROGIEZ

1450. Number of Students Doing Homework at a Given Time LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.