title: Minimum Steps To Delete A String After Repeated Deletion Of Palindrome Substrings
signature: function minimumStepsToDeleteAStringAfterRepeatedDeletionOfPalindromeSubstrings(str: string): number {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(str: string, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(str),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("YCtLQtHLwr", 8);
    console.log(`TEST-0...${result}`);
  
    result = driver("47713514383248", 7);
    console.log(`TEST-1...${result}`);
  
    result = driver("0100101001111", 3);
    console.log(`TEST-2...${result}`);
  
    result = driver("XfdIYVn", 7);
    console.log(`TEST-3...${result}`);
  
    result = driver("45499225407", 5);
    console.log(`TEST-4...${result}`);
  
    result = driver("000100111001", 2);
    console.log(`TEST-5...${result}`);
  
    result = driver("ZoUQhQwoap", 6);
    console.log(`TEST-6...${result}`);
  
    result = driver("18579027952", 7);
    console.log(`TEST-7...${result}`);
  
    result = driver("00000001111", 2);
    console.log(`TEST-8...${result}`);
  
    result = driver("JD", 2);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings(str):
      N = len(str)
      dp = [[0 for x in range((N + 1))] for y in range((N + 1))]
      for l in range(1, (N + 1)):
          i = 0
          j = (l - 1)
          while (j < N):
              if (l == 1):
                  dp[i][j] = 1
              else:
                  dp[i][j] = (1 + dp[(i + 1)][j])
                  if (str[i] == str[(i + 1)]):
                      dp[i][j] = min((1 + dp[(i + 2)][j]), dp[i][j])
                  for K in range((i + 2), (j + 1)):
                      if (str[i] == str[K]):
                          dp[i][j] = min((dp[(i + 1)][(K - 1)] + dp[(K + 1)][j]), dp[i][j])
              i += 1
              j += 1
      return dp[0][(N - 1)]
source_cpp: int minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings(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 len = 1;
    len <= N;
    len ++ ) {
      for ( int i = 0, j = len - 1;
      j < N;
      i ++, j ++ ) {
        if ( len == 1 ) dp [ i ] [ j ] = 1;
        else {
          dp [ i ] [ j ] = 1 + dp [ i + 1 ] [ j ];
          if ( str [ i ] == str [ i + 1 ] ) dp [ i ] [ j ] = min ( 1 + dp [ i + 2 ] [ j ], dp [ i ] [ j ] );
          for ( int K = i + 2;
          K <= j;
          K ++ ) if ( str [ i ] == str [ K ] ) dp [ i ] [ j ] = min ( dp [ i + 1 ] [ K - 1 ] + dp [ K + 1 ] [ j ], dp [ i ] [ j ] );
        }
      }
    }
    return dp [ 0 ] [ N - 1 ];
  }