Activity Selection
Learn how to solve the 'Activity Selection' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Write a function activity_selection(start, end) that takes two lists start and end representing the start and end times of activities. Find the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time. Two activities are non-overlapping if the start time of the second is greater than or equal to the end time of the first.
- •1 <= len(start) == len(end) <= 10^5
- •0 <= start[i] < end[i] <= 10^9
Examples
activity_selection([1, 3, 0, 5, 8, 5], [2, 4, 6, 7, 9, 9])
4
A person can perform at most 4 activities: [1,2], [3,4], [5,7], and [8,9].
activity_selection([10, 12, 20], [20, 25, 30])
2
Two activities can be performed: [10,20] and [20,30].
Need a Hint?
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.