Created
March 11, 2020 18:27
-
-
Save raunaqsingh2020/32c848adbbe7a08069d5453a1c3c11fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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