MCPcopy Create free account
hub / github.com/apna-college/Alpha / MaxChainLength

Class MaxChainLength

15_Greedy/MaxChainLength.java:4–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import java.util.Comparator;
3
4public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…