public static boolean isSequence(int[][] a){ int n = a.length; /* 1) Get the minimum element in array */ int min = getMinValue(a); /* 2) Get the maximum element in array */ int max = getMaxValue(a); if (n < 1) return false; /* 3) max - min + 1 is equal to n, then only check all elements */ if (max - min + 1 == n) { /* Create a temp array to hold visited flag of all elements. Note that, calloc is used here so that all values are initialized as false */ boolean visited[] = new boolean[n]; int i; for (i = 0; i < n; i++) { for (int j = 0; j < a[i].length; j++) { if (visited[a[i][j] - min] != false) return false; visited[a[i][j] - min] = true; } } /* If we see an element again, then return false */ /* If visited first time, then mark the element as visited */ /* If all elements occur once, then return true */ return true; } return false; // if (max - min + 1 != n) }