title: Longest Repeating And Non Overlapping Substring
signature: def longestRepeatingAndNonOverlappingSubstring(str: String) = {
source_py: def longest_repeating_and_non_overlapping_substring(str):
      n = len(str)
      LCSRe = [[0 for x in range((n + 1))] for y in range((n + 1))]
      res = ''
      res_length = 0
      index = 0
      for i in range(1, (n + 1)):
          for j in range((i + 1), (n + 1)):
              if ((str[(i - 1)] == str[(j - 1)]) and (LCSRe[(i - 1)][(j - 1)] < (j - i))):
                  LCSRe[i][j] = (LCSRe[(i - 1)][(j - 1)] + 1)
                  if (LCSRe[i][j] > res_length):
                      res_length = LCSRe[i][j]
                      index = max(i, index)
              else:
                  LCSRe[i][j] = 0
      if (res_length > 0):
          for i in range(((index - res_length) + 1), (index + 1)):
              res = (res + str[(i - 1)])
      return res
source_cpp: string longest_repeating_and_non_overlapping_substring(string str) {
    int n = str . length ( );
    int LCSRe [ n + 1 ] [ n + 1 ];
    memset ( LCSRe, 0, sizeof ( LCSRe ) );
    string res;
    int res_length = 0;
    int i, index = 0;
    for ( i = 1;
    i <= n;
    i ++ ) {
      for ( int j = i + 1;
      j <= n;
      j ++ ) {
        if ( str [ i - 1 ] == str [ j - 1 ] && LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) {
          LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1;
          if ( LCSRe [ i ] [ j ] > res_length ) {
            res_length = LCSRe [ i ] [ j ];
            index = max ( i, index );
          }
        }
        else LCSRe [ i ] [ j ] = 0;
      }
    }
    if ( res_length > 0 ) for ( i = index - res_length + 1;
    i <= index;
    i ++ ) res . push_back ( str [ i - 1 ] );
    return res;
  }