title: Count Palindromic Subsequence Given String
signature: class Solution {
  
      public Integer countPalindromicSubsequenceGivenString(String str) {
source_py: def count_palindromic_subsequence_given_string(str):
      N = len(str)
      cps = [[0 for i in range((N + 2))] for j in range((N + 2))]
      for i in range(N):
          cps[i][i] = 1
      for L in range(2, (N + 1)):
          for i in range(N):
              k = ((L + i) - 1)
              if (k < N):
                  if (str[i] == str[k]):
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) + 1)
                  else:
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) - cps[(i + 1)][(k - 1)])
      return cps[0][(N - 1)]
source_cpp: int count_palindromic_subsequence_given_string(string str) {
    int N = str . length ( );
    int cps [ N + 1 ] [ N + 1 ];
    memset ( cps, 0, sizeof ( cps ) );
    for ( int i = 0;
    i < N;
    i ++ ) cps [ i ] [ i ] = 1;
    for ( int L = 2;
    L <= N;
    L ++ ) {
      for ( int i = 0;
      i < N;
      i ++ ) {
        int k = L + i - 1;
        if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1;
        else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ];
      }
    }
    return cps [ 0 ] [ N - 1 ];
  }
question_info.extension: java
question_info.entry_fn_name: countPalindromicSubsequenceGivenString
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"str": "R"}}, {"idx": 1, "outputs": 10, "inputs": {"str": "2956350"}}, {"idx": 2, "outputs": 2798, "inputs": {"str": "11100111110101"}}, {"idx": 3, "outputs": 20, "inputs": {"str": "TZTDLIIfAD"}}, {"idx": 4, "outputs": 2, "inputs": {"str": "98"}}, {"idx": 5, "outputs": 270, "inputs": {"str": "1100100001"}}, {"idx": 6, "outputs": 8, "inputs": {"str": "oKwGeatf"}}, {"idx": 7, "outputs": 2, "inputs": {"str": "19"}}, {"idx": 8, "outputs": 563, "inputs": {"str": "00010110100"}}, {"idx": 9, "outputs": 3, "inputs": {"str": "Cyq"}}]
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("R", 1);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("2956350", 10);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("11100111110101", 2798);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("TZTDLIIfAD", 20);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("98", 2);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("1100100001", 270);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("oKwGeatf", 8);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("19", 2);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("00010110100", 563);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("Cyq", 3);
          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__