forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivity_Selection.dart
38 lines (36 loc) · 966 Bytes
/
Activity_Selection.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* The Activity Selection Problem
You are given n activities with their start and finish times.
Select 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.
*/
class ActivitySelection
{
void activities(List<int> start, List<int> finish, int n)
{
int i = 0;
print('$i ');
for (int j = 1; j < n; j++)
{
if (start[j] >= finish[i])
{
print('$j ');
i = j;
}
}
}
}
void main()
{
List<int> start = [0, 5, 5, 4, 5, 8]; // starting time of the activities
List<int> finish = [2, 7, 6, 8, 9, 14]; // finishin time of the activities
int n = start.length;
ActivitySelection selection = new ActivitySelection();
selection.activities(start, finish, n);
}
/*
Sample input
Start : 0 5 5 4 5 8
Finish: 2 7 6 8 9 14
Sample Output
0 1 5
*/