- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Number of Programmer Worked on given Time in Python

Suppose we have list of intervals and another input time. In each interval the structure is [start, end], this is representing the times when a programmer worked. We have to find the number of programmers that were working at time.

So, if the input is like interval = [[2, 6],[4, 10],[5, 9],[11, 14]], time = 5, then the output will be 3 as at time 5, there are three programmers, working [2, 6], [4, 10], [5, 9]

To solve this, we will follow these steps −

- count := 0
- for each interval in intervals, do
- if start of interval <= time and end of interval >= time, then
- count := count + 1

- if start of interval <= time and end of interval >= time, then
- return count

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, intervals, time): count = 0 for interval in intervals: if interval[0] <= time and interval[1] >= time: count += 1 return count ob = Solution() interval = [[2, 6],[4, 10],[5, 9],[11, 14]] time = 5 print(ob.solve(interval, time))

## Input

[[2, 6],[4, 10],[5, 9],[11, 14]], 5

## Output

3

- Related Questions & Answers
- Program to find in which interval how many tasks are worked on in Python
- Programmer's view of 6800
- Programmer's view of 8051
- Program to find nearest time by reusing same digits of given time in python
- Program to find maximum number of courses we can take based on interval time in Python?
- Programmer's view of Z-80
- Programmer's view of 8085 Microprocessor
- Queries on number of Binary sub-matrices of Given size in C++
- Python Pandas - Return the string alias of the Time series frequency applied on the given Period object
- Python program to find difference between current time and given time
- C++ Queries on Probability of Even or Odd Number in Given Ranges
- Program to find number of bit 1 in the given number in Python
- How to find the number of digits in a given number using Python?
- Find the time which is palindromic and comes after the given time in Python
- Python - Largest number possible from list of given numbers

Advertisements