code: public static int[] computeLCP(int[] input, final int start, final int length,
                                     int[] sa) {
          final int[] rank = new int[length];
          for (int i = 0; i < length; i++)
              rank[sa[i]] = i;
          int h = 0;
          final int[] lcp = new int[length];
          for (int i = 0; i < length; i++) {
              int k = rank[i];
              if (k == 0) {
                  lcp[k] = -1;
              } else {
                  final int j = sa[k - 1];
                  while (i + h < length && j + h < length
                      && input[start + i + h] == input[start + j + h]) {
                      h++;
                  }
                  lcp[k] = h;
              }
              if (h > 0) h--;
          }
  
          return lcp;
      }
docs: Calculate longest prefix (LCP) array for an existing suffix array and input. Index
  <code>i</code> of the returned array indicates the length of the common prefix
  between suffix <code>i</code> and <code>i-1</code>. The 0-th
  index has a constant value of <code>-1</code>.
  <p>
  The algorithm used to compute the LCP comes from
  <tt>T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park. Linear-time longest-common-prefix
  computation in suffix arrays and its applications. In Proc. 12th Symposium on Combinatorial
  Pattern Matching (CPM ’01), pages 181–192. Springer-Verlag LNCS n. 2089, 2001.</tt>