Competitive ProgrammingEasy

Activity Selection

Detailed guide and Python implementation for the 'Activity Selection' problem.

Problem Statement

Easy

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.

Constraints
  • 1 <= len(start) == len(end) <= 10^5
  • 0 <= start[i] < end[i] <= 10^9

Examples

Example 1
Input
activity_selection([1, 3, 0, 5, 8, 5], [2, 4, 6, 7, 9, 9])
Output
4
Explanation

A person can perform at most 4 activities: [1,2], [3,4], [5,7], and [8,9].

Example 2
Input
activity_selection([10, 12, 20], [20, 25, 30])
Output
2
Explanation

Two activities can be performed: [10,20] and [20,30].

Need a Hint?
Consider using Greedy-specific data structures like sets or heaps.
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.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.