title: Longest Repeating Subsequence
signature: class Solution {
  
      public Integer longestRepeatingSubsequence(String str) {
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 ];
  }
question_info.extension: java
question_info.entry_fn_name: longestRepeatingSubsequence
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"str": "JxZFz"}}, {"idx": 1, "outputs": 3, "inputs": {"str": "7648992235770"}}, {"idx": 2, "outputs": 6, "inputs": {"str": "11100000"}}, {"idx": 3, "outputs": 1, "inputs": {"str": "cRN  SgYjPsctJ"}}, {"idx": 4, "outputs": 1, "inputs": {"str": "434"}}, {"idx": 5, "outputs": 0, "inputs": {"str": "1"}}, {"idx": 6, "outputs": 1, "inputs": {"str": "JRfZIAsbrPBZ"}}, {"idx": 7, "outputs": 3, "inputs": {"str": "03779368305592"}}, {"idx": 8, "outputs": 5, "inputs": {"str": "1111000"}}, {"idx": 9, "outputs": 0, "inputs": {"str": "BkULuIi"}}]
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, Integer 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("JxZFz", 0);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("7648992235770", 3);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("11100000", 6);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("cRN  SgYjPsctJ", 1);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("434", 1);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("1", 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("JRfZIAsbrPBZ", 1);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("03779368305592", 3);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("1111000", 5);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("BkULuIi", 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String str, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(str),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer 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__