Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithasudhakar authored Nov 25, 2024
1 parent 37ac348 commit 330a0c4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Math/ActivitySelection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

class ActivitySelection{

static ArrayList<Integer> seq = new ArrayList<>();

static void activity(int[] start, int[] end){
int j = 0;
int i = 1;

seq.add(j);
while(i<start.length){
if(start[i]>=end[j]){
seq.add(i);
j = i;
}
i++;
}
}

public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] start = new int[n];
int[] end = new int[n];
for(int i = 0; i<n; i++){
System.out.println("Enter start["+i+"]: " );
start[i] = input.nextInt();
System.out.println("Enter end["+i+"]: " );
end[i] = input.nextInt();
}
activity(start, end);
for(int ele: seq){
System.out.println(ele);
}
}
}

0 comments on commit 330a0c4

Please sign in to comment.