title: Longest Repeating Subsequence
signature: function longest_repeating_subsequence(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.entry_fn_name: longest_repeating_subsequence
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(str, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(str) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("JxZFz", 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver("7648992235770", 3)
      print(string.format("TEST-1...%s",result))
  
      result = driver("11100000", 6)
      print(string.format("TEST-2...%s",result))
  
      result = driver("cRN  SgYjPsctJ", 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver("434", 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver("1", 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver("JRfZIAsbrPBZ", 1)
      print(string.format("TEST-6...%s",result))
  
      result = driver("03779368305592", 3)
      print(string.format("TEST-7...%s",result))
  
      result = driver("1111000", 5)
      print(string.format("TEST-8...%s",result))
  
      result = driver("BkULuIi", 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
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"}}]