MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / print_max_activities

Function print_max_activities

other/activity_selection.py:11–33  ·  view source on GitHub ↗

>>> start = [1, 3, 0, 5, 8, 5] >>> finish = [2, 4, 6, 7, 9, 9] >>> print_max_activities(start, finish) The following activities are selected: 0,1,3,4,

(start: list[int], finish: list[int])

Source from the content-addressed store, hash-verified

9
10
11def print_max_activities(start: list[int], finish: list[int]) -> None:
12 """
13 >>> start = [1, 3, 0, 5, 8, 5]
14 >>> finish = [2, 4, 6, 7, 9, 9]
15 >>> print_max_activities(start, finish)
16 The following activities are selected:
17 0,1,3,4,
18 """
19 n = len(finish)
20 print("The following activities are selected:")
21
22 # The first activity is always selected
23 i = 0
24 print(i, end=",")
25
26 # Consider rest of the activities
27 for j in range(n):
28 # If this activity has start time greater than
29 # or equal to the finish time of previously
30 # selected activity, then select it
31 if start[j] >= finish[i]:
32 print(j, end=",")
33 i = j
34
35
36if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected