title: Longest Repeating And Non Overlapping Substring
signature: string longestRepeatingAndNonOverlappingSubstring(string str) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(string actual, string expected){
      return actual == expected;
  }
  
  string driver(string str, string expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver("fbfHTjE", "f"); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver("09285256323", "2"); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver("0011000101110", "001"); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver("ue JkVZTt", ""); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver("48387612426300", "4"); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver("010", "0"); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver("ddRrUz", "d"); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver("1049162633793", "1"); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver("100011", "1"); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver("iJfadiVaQqv", "i"); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }