Activity Selection
Detailed guide and Python implementation for the 'Activity Selection' problem.
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 input structures
- Single element inputs
- Large numerical bounds
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.