[
greedy
intervals
sort
]
BinarySearch 0394 Class Scheduling
Problem statement
https://binarysearch.com/problems/Class-Scheduling/
Solution
It is equal to Leetcode 0452. Minimum Number of Arrows to Burst Balloons.
Complexity
It is O(n log n)
for time and O(n)
for space.
Code
class Solution:
def solve(self, points):
points.sort(key = lambda x: x[1])
n, count = len(points), 1
if n == 0: return 0
curr = points[0]
for i in range(n):
if curr[1] < points[i][0]:
count += 1
curr = points[i]
return count