title: Longest Repeating And Non Overlapping Substring
signature: longestRepeatingAndNonOverlappingSubstring :: String -> String
  longestRepeatingAndNonOverlappingSubstring str = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: String -> String -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: String -> String -> String
  driver str expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME str) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ("fbfHTjE") ("f") )
  
      printf "TEST-1...%s\n" (driver ("09285256323") ("2") )
  
      printf "TEST-2...%s\n" (driver ("0011000101110") ("001") )
  
      printf "TEST-3...%s\n" (driver ("ue JkVZTt") ("") )
  
      printf "TEST-4...%s\n" (driver ("48387612426300") ("4") )
  
      printf "TEST-5...%s\n" (driver ("010") ("0") )
  
      printf "TEST-6...%s\n" (driver ("ddRrUz") ("d") )
  
      printf "TEST-7...%s\n" (driver ("1049162633793") ("1") )
  
      printf "TEST-8...%s\n" (driver ("100011") ("1") )
  
      printf "TEST-9...%s\n" (driver ("iJfadiVaQqv") ("i") )
  
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;
  }