| 2 | import java.util.Comparator; |
| 3 | |
| 4 | public class MaxChainLength { |
| 5 | public static void main(String args[]) { |
| 6 | int pairs[][] = {{5, 24}, {39, 60}, {5, 28}, {27, 40}, {50, 90}}; |
| 7 | |
| 8 | Arrays.sort(pairs, Comparator.comparingDouble(o -> o[1])); |
| 9 | |
| 10 | int maxLen = 1; |
| 11 | int prevEnd = pairs[0][1]; |
| 12 | for(int i=1; i<pairs.length; i++) { |
| 13 | if(pairs[i][0] > prevEnd) { |
| 14 | maxLen++; |
| 15 | prevEnd = pairs[i][1]; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | System.out.println("max chain length = "+ maxLen); |
| 20 | } |
| 21 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…