title: Longest Repeating Subsequence
signature: pub fn longest_repeating_subsequence(str: String) -> i32 {
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: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(str: String, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(str), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "JxZFz".to_string(), 
        0
      ));
      
      println!("TEST-1...{}", driver(
        "7648992235770".to_string(), 
        3
      ));
      
      println!("TEST-2...{}", driver(
        "11100000".to_string(), 
        6
      ));
      
      println!("TEST-3...{}", driver(
        "cRN  SgYjPsctJ".to_string(), 
        1
      ));
      
      println!("TEST-4...{}", driver(
        "434".to_string(), 
        1
      ));
      
      println!("TEST-5...{}", driver(
        "1".to_string(), 
        0
      ));
      
      println!("TEST-6...{}", driver(
        "JRfZIAsbrPBZ".to_string(), 
        1
      ));
      
      println!("TEST-7...{}", driver(
        "03779368305592".to_string(), 
        3
      ));
      
      println!("TEST-8...{}", driver(
        "1111000".to_string(), 
        5
      ));
      
      println!("TEST-9...{}", driver(
        "BkULuIi".to_string(), 
        0
      ));
      
  }
source_py: def longest_repeating_subsequence(str):
      n = len(str)
      dp = ([([0] * (n + 1))] * (n + 1))
      for i in range(1, (n + 1)):
          for j in range(1, (n + 1)):
              if ((str[(i - 1)] == str[(j - 1)]) and (i != j)):
                  dp[i][j] = (1 + dp[(i - 1)][(j - 1)])
              else:
                  dp[i][j] = max(dp[i][(j - 1)], dp[(i - 1)][j])
      return dp[n][n]
source_cpp: int longest_repeating_subsequence(string str) {
    int n = str . length ( );
    int dp [ n + 1 ] [ n + 1 ];
    for ( int i = 0;
    i <= n;
    i ++ ) for ( int j = 0;
    j <= n;
    j ++ ) dp [ i ] [ j ] = 0;
    for ( int i = 1;
    i <= n;
    i ++ ) {
      for ( int j = 1;
      j <= n;
      j ++ ) {
        if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ];
        else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ], dp [ i - 1 ] [ j ] );
      }
    }
    return dp [ n ] [ n ];
  }