title: Longest Palindrome Subsequence Space
signature: class Solution {
  
      public int LongestPalindromeSubsequenceSpace(string s) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(string s, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(s); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  " E", 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  "0845591950", 
                  7
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  "00101011", 
                  5
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  "pLSvlwrACvFaoT", 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  "7246", 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  "1010101100000", 
                  8
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  "obPkcLSFp", 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  "914757557818", 
                  7
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  "1", 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  "PKvUWIQ", 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 ];
  }