title: Longest Repeating And Non Overlapping Substring
signature: longest_repeating_and_non_overlapping_substring <- function(str) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(str, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(str), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "fbfHTjE", 
          "f"
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "09285256323", 
          "2"
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "0011000101110", 
          "001"
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "ue JkVZTt", 
          ""
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "48387612426300", 
          "4"
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "010", 
          "0"
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "ddRrUz", 
          "d"
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "1049162633793", 
          "1"
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "100011", 
          "1"
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "iJfadiVaQqv", 
          "i"
      )))
  
  }
  
  main()
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;
  }