- 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 find minimum number of movie theatres required to show all movies in python

Suppose we have a list of intervals for different movie showings (they can be overlapped), we have to find the minimum number of theatres required to be able to show all of the movies.

So, if the input is like intervals = [[20, 65],[0, 40],[50, 140]], then the output will be 2, as [20, 65] and [0, 40] are overlapping. [20, 65] and [50, 140] are also overlapping but [0, 40] and [50, 140] are not. So we need 2 theaters.

To solve this, we will follow these steps:

- t := a new list
- for each interval [a, b] in intervals, do
- insert [a, 1] at the end of t
- insert [b, -1] at the end of t

- ans := 0, count := 0
- for each pair (x, d) in t in sorted form, do
- count := count + d
- ans := maximum of ans and count

- return ans

Let us see the following implementation to get better understanding:

## Example Code

class Solution: def solve(self, intervals): t = [] for a, b in intervals: t.append((a, 1)) t.append((b, -1)) ans = count = 0 for x, d in sorted(t): count += d ans = max(ans, count) return ans ob = Solution() intervals = [[20, 65],[0, 40],[50, 140]] print(ob.solve(intervals))

## Input

[[20, 65],[0, 40],[50, 140]]

## Output

2

- Related Questions & Answers
- Program to find minimum number of busses are required to pass through all stops in Python
- Program to find minimum number of pins required to hang all banners in C++
- Program to find number of minimum steps required to meet all person at any cell in Python
- Program to find minimum number of operations required to make one number to another in Python
- Program to find minimum number of hops required to reach end position in Python
- Program to find minimum number of buses required to reach final target in python
- Program to find minimum number of flips required to have alternating values in Python
- Program to find minimum number of operations required to make lists strictly Increasing in python
- Program to find minimum number of operations required to make one string substring of other in Python
- Program to find minimum number of bricks required to make k towers of same height in Python
- Program to find minimum number of vertices to reach all nodes using Python
- Program to find minimum number of steps required to catch the opponent in C++
- Program to find minimum number of deletions required from two ends to make list balanced in Python
- Program to count number of minimum swaps required to make it palindrome in Python
- Program to find minimum swaps required to make given anagram in python

Advertisements