title: Longest Repeating Subsequence
signature: int longestRepeatingSubsequence(string str) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(string str, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver("JxZFz", 0); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver("7648992235770", 3); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver("11100000", 6); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver("cRN  SgYjPsctJ", 1); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver("434", 1); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver("1", 0); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver("JRfZIAsbrPBZ", 1); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver("03779368305592", 3); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver("1111000", 5); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver("BkULuIi", 0); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 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 ];
  }