title: Longest Palindrome Subsequence Space
signature: class Solution {
  
      public Integer longestPalindromeSubsequenceSpace(String s) {
source_py: def longest_palindrome_subsequence_space(s):
      n = len(s)
      a = ([0] * n)
      for i in range((n - 1), (- 1), (- 1)):
          back_up = 0
          for j in range(i, n):
              if (j == i):
                  a[j] = 1
              elif (s[i] == s[j]):
                  temp = a[j]
                  a[j] = (back_up + 2)
                  back_up = temp
              else:
                  back_up = a[j]
                  a[j] = max(a[(j - 1)], a[j])
      return a[(n - 1)]
source_cpp: int longest_palindrome_subsequence_space(string & s) {
    int n = s . length ( );
    int a [ n ];
    for ( int i = n - 1;
    i >= 0;
    i -- ) {
      int back_up = 0;
      for ( int j = i;
      j < n;
      j ++ ) {
        if ( j == i ) a [ j ] = 1;
        else if ( s [ i ] == s [ j ] ) {
          int temp = a [ j ];
          a [ j ] = back_up + 2;
          back_up = temp;
        }
        else {
          back_up = a [ j ];
          a [ j ] = max ( a [ j - 1 ], a [ j ] );
        }
      }
    }
    return a [ n - 1 ];
  }
question_info.extension: java
question_info.entry_fn_name: longestPalindromeSubsequenceSpace
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"s": " E"}}, {"idx": 1, "outputs": 7, "inputs": {"s": "0845591950"}}, {"idx": 2, "outputs": 5, "inputs": {"s": "00101011"}}, {"idx": 3, "outputs": 3, "inputs": {"s": "pLSvlwrACvFaoT"}}, {"idx": 4, "outputs": 1, "inputs": {"s": "7246"}}, {"idx": 5, "outputs": 8, "inputs": {"s": "1010101100000"}}, {"idx": 6, "outputs": 1, "inputs": {"s": "obPkcLSFp"}}, {"idx": 7, "outputs": 7, "inputs": {"s": "914757557818"}}, {"idx": 8, "outputs": 1, "inputs": {"s": "1"}}, {"idx": 9, "outputs": 1, "inputs": {"s": "PKvUWIQ"}}]
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 s, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(s,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(" E", 1);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("0845591950", 7);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("00101011", 5);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("pLSvlwrACvFaoT", 3);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("7246", 1);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("1010101100000", 8);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("obPkcLSFp", 1);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("914757557818", 7);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("1", 1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("PKvUWIQ", 1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String s, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(s),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__