Skip to content

Instantly share code, notes, and snippets.

@raunaqsingh2020
Created March 11, 2020 18:27
Show Gist options
  • Save raunaqsingh2020/32c848adbbe7a08069d5453a1c3c11fd to your computer and use it in GitHub Desktop.
Save raunaqsingh2020/32c848adbbe7a08069d5453a1c3c11fd to your computer and use it in GitHub Desktop.
import java.util.*;
public class Activities
{
public Activities()
{
int[] start = {1,3,0,5,8,5};
int[] finish = {2,4,6,7,9,9};
System.out.println("Start Times: " + Arrays.toString(start));
System.out.println("End Times: " + Arrays.toString(finish));
System.out.println(maxActivities(start, finish));
}
public ArrayList<Integer> maxActivities(int[] start, int[] finish)
{
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(0);
for(int i = 1; i < start.length; i++){
if(start[i] >= finish[list.get(list.size()-1)]){
list.add(i);
}
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment