- 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

# Program to count number of intervals which are intersecting at given point in Python

Suppose we have a list of intervals and a value called point. Each interval interval[i] contains [si, ei] represents start time and end time of interval i (both inclusive). We have to find the number of intervals that are intersecting at given point.

So, if the input is like intervals = [[2, 6],[4, 10],[5, 9],[11, 14]] point = 5, then the output will be 3, because at time 5, there are 3 intervals those are [3, 6], [4, 10], [5, 9]

To solve this, we will follow these steps −

count := 0

for each start time i and end time j in intervals, do

if point >= i and point <= j, then

count := count + 1

return count

## Example

Let us see the following implementation to get better understanding

def solve(intervals, point): count = 0 for i, j in intervals: if point >= i and point <= j: count += 1 return count intervals = [[2, 6],[4, 10],[5, 9],[11, 14]] point = 5 print(solve(intervals, point))

## Input

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

## Output

3

- Related Questions & Answers
- Find Intersecting Intervals in Python
- Count the number of intervals in which a given value lies in C++
- Program to count number of intervals that is totally contained inside other intervals in Python
- Program to count number of elements are placed at correct position in Python
- 8085 program to count number of elements which are less than 0A
- Program to find number of elements in all permutation which are following given conditions in Python
- Program to count minimum number of animals which have no predator in Python
- Program to count number of islands in a given matrix in Python
- Program to count number of paths with cost k from start to end point in Python
- Program to count number of square submatrices in given binary matrix in Python
- Python Program to Count Number of Non Leaf Nodes of a given Tree
- Python program to count number of vowels using set in a given string
- Program to count number of unique paths that includes given edges in Python
- Program to count number of ways to win at most k consecutive games in Python
- Program to return number of smaller elements at right of the given list in Python

Advertisements