Answer 1 Python version

mail@pastecode.io avatar
unknown
python
7 months ago
493 B
1
Indexable
Never
class Range:
    def __init__(self, l, r):
        self.l = l 
        self.r = r
n = int(input()) 
ranges = []

for _ in range(n):
    l, r = map(int, input().split()) 
    ranges.append(Range(l, r))
# Sort the ranges based on their 'l' values. 
ranges.sort(key=lambda x: x.l)

q = []
max_count = 0 
current_end_time = 0

for i in range(n):
    while q and q[0] <= ranges[i].l:
        q.pop(0) 
    q.append(ranges[i].r) 
    q.sort()
    max_count = max(max_count, len(q)) 
print(max_count)