title: Longest Repeating And Non Overlapping Substring
signature: function longest_repeating_and_non_overlapping_substring(str)
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;
  }
question_info.entry_fn_name: longest_repeating_and_non_overlapping_substring
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(str, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(str) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("fbfHTjE", "f")
      print(string.format("TEST-0...%s",result))
  
      result = driver("09285256323", "2")
      print(string.format("TEST-1...%s",result))
  
      result = driver("0011000101110", "001")
      print(string.format("TEST-2...%s",result))
  
      result = driver("ue JkVZTt", "")
      print(string.format("TEST-3...%s",result))
  
      result = driver("48387612426300", "4")
      print(string.format("TEST-4...%s",result))
  
      result = driver("010", "0")
      print(string.format("TEST-5...%s",result))
  
      result = driver("ddRrUz", "d")
      print(string.format("TEST-6...%s",result))
  
      result = driver("1049162633793", "1")
      print(string.format("TEST-7...%s",result))
  
      result = driver("100011", "1")
      print(string.format("TEST-8...%s",result))
  
      result = driver("iJfadiVaQqv", "i")
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": "f", "inputs": {"str": "fbfHTjE"}}, {"idx": 1, "outputs": "2", "inputs": {"str": "09285256323"}}, {"idx": 2, "outputs": "001", "inputs": {"str": "0011000101110"}}, {"idx": 3, "outputs": "", "inputs": {"str": "ue JkVZTt"}}, {"idx": 4, "outputs": "4", "inputs": {"str": "48387612426300"}}, {"idx": 5, "outputs": "0", "inputs": {"str": "010"}}, {"idx": 6, "outputs": "d", "inputs": {"str": "ddRrUz"}}, {"idx": 7, "outputs": "1", "inputs": {"str": "1049162633793"}}, {"idx": 8, "outputs": "1", "inputs": {"str": "100011"}}, {"idx": 9, "outputs": "i", "inputs": {"str": "iJfadiVaQqv"}}]