Back to photostream

Number of Students Doing Homework at a Given Time Leetcode Solution

The problem Number of Students Doing Homework at a Given Time Leetcode Solution asks us to find the number of students working on their homework at a given time. The problem is very clear, the title itself is already able to explain the whole problem. We are given a query time and the time the students work on their homework. So, using this information we are asked to find the number of students who are doing their homework during the query time. So, as usual before directly jumping into the solution. Let us check a few examples.

 

startTime = , endTime = , queryTime = 4

1

Explanation: We have three students out of which only 1 student works on his/her homework during the query time. Because there is only a single child starting his homework at time = 3, and completing it at time = 7.

startTime = , endTime = , queryTime = 4

1

Explanation: We have a single student who starts his/her homework at the same as that of the query time. Thus the output is also 1.

Approach for Number of Students Doing Homework at a Given Time Leetcode Solution

The problem asked us to find the number of students who are working on their homework during the query time. We are provided with the start and end times of students' homework activities in the form of a vector or array. Using this information, we try to find the required value.

 

We can easily solve the problem just by traversing over the given information. The given information is the starting and end time of the homework activity.

 

www.tutorialcup.com/leetcode-solutions/number-of-students...

25 views
0 faves
0 comments
Uploaded on August 30, 2021