title: Longest Repeating And Non Overlapping Substring
signature: class Solution {
  
      public String longestRepeatingAndNonOverlappingSubstring(String 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.extension: java
question_info.entry_fn_name: longestRepeatingAndNonOverlappingSubstring
question_info.entry_cls_name: Solution
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"}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(String str, String expected){
          try{
              Driver driver = new Driver();
              if (driver.run(str,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution("fbfHTjE", "f");
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("09285256323", "2");
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("0011000101110", "001");
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("ue JkVZTt", "");
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("48387612426300", "4");
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("010", "0");
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("ddRrUz", "d");
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("1049162633793", "1");
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("100011", "1");
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("iJfadiVaQqv", "i");
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String str, String expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(str),expected);
      }
      
      public boolean validateSolution(String actual, String expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__