title: Longest Repeating And Non Overlapping Substring
signature: pub fn longest_repeating_and_non_overlapping_substring(str: String) -> String {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: String, expected: String)->bool{
  return actual==expected
  }
  pub fn driver(str: String, expected: String)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(str), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "fbfHTjE".to_string(), 
        "f".to_string()
      ));
      
      println!("TEST-1...{}", driver(
        "09285256323".to_string(), 
        "2".to_string()
      ));
      
      println!("TEST-2...{}", driver(
        "0011000101110".to_string(), 
        "001".to_string()
      ));
      
      println!("TEST-3...{}", driver(
        "ue JkVZTt".to_string(), 
        "".to_string()
      ));
      
      println!("TEST-4...{}", driver(
        "48387612426300".to_string(), 
        "4".to_string()
      ));
      
      println!("TEST-5...{}", driver(
        "010".to_string(), 
        "0".to_string()
      ));
      
      println!("TEST-6...{}", driver(
        "ddRrUz".to_string(), 
        "d".to_string()
      ));
      
      println!("TEST-7...{}", driver(
        "1049162633793".to_string(), 
        "1".to_string()
      ));
      
      println!("TEST-8...{}", driver(
        "100011".to_string(), 
        "1".to_string()
      ));
      
      println!("TEST-9...{}", driver(
        "iJfadiVaQqv".to_string(), 
        "i".to_string()
      ));
      
  }
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;
  }