human
Can you provide a code to activity Selection Problem and the other steps required given the following:
Activity Selection Problem | Greedy Algo | Returns count of the maximum set of activities that can be done by a single person , one at a time ..
Sort jobs according to finish time.
The first activity always gets selected.
Consider rest of the activities.
If this activity has start time greater than or equal to the finish time of previously selected activity , then select it.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to activity Selection Problem and the other steps required.
 def MaxActivities ( arr , n ) :
	selected = [ ]
	Activity . sort ( key = lambda x : x [ 1 ] )
	i = 0
	selected . append ( arr [ i ] )
	for j in range ( 1 , n ) :
	if arr [ j ] [ 0 ] >= arr [ i ] [ 1 ] :
		selected . append ( arr [ j ] )
		i = j
	return selected
Activity = [ [ 5 , 9 ] , [ 1 , 2 ] , [ 3 , 4 ] , [ 0 , 6 ] , [ 5 , 7 ] , [ 8 , 9 ] ]
n = len ( Activity )
selected = MaxActivities ( Activity , n )
print ( " Following ▁ activities ▁ are ▁ selected ▁ : " )
print ( selected )