title: Minimum Steps To Delete A String After Repeated Deletion Of Palindrome Substrings
signature: function minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings(str)
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 ];
  }
question_info.entry_fn_name: minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings
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("YCtLQtHLwr", 8)
      print(string.format("TEST-0...%s",result))
  
      result = driver("47713514383248", 7)
      print(string.format("TEST-1...%s",result))
  
      result = driver("0100101001111", 3)
      print(string.format("TEST-2...%s",result))
  
      result = driver("XfdIYVn", 7)
      print(string.format("TEST-3...%s",result))
  
      result = driver("45499225407", 5)
      print(string.format("TEST-4...%s",result))
  
      result = driver("000100111001", 2)
      print(string.format("TEST-5...%s",result))
  
      result = driver("ZoUQhQwoap", 6)
      print(string.format("TEST-6...%s",result))
  
      result = driver("18579027952", 7)
      print(string.format("TEST-7...%s",result))
  
      result = driver("00000001111", 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver("JD", 2)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 8, "inputs": {"str": "YCtLQtHLwr"}}, {"idx": 1, "outputs": 7, "inputs": {"str": "47713514383248"}}, {"idx": 2, "outputs": 3, "inputs": {"str": "0100101001111"}}, {"idx": 3, "outputs": 7, "inputs": {"str": "XfdIYVn"}}, {"idx": 4, "outputs": 5, "inputs": {"str": "45499225407"}}, {"idx": 5, "outputs": 2, "inputs": {"str": "000100111001"}}, {"idx": 6, "outputs": 6, "inputs": {"str": "ZoUQhQwoap"}}, {"idx": 7, "outputs": 7, "inputs": {"str": "18579027952"}}, {"idx": 8, "outputs": 2, "inputs": {"str": "00000001111"}}, {"idx": 9, "outputs": 2, "inputs": {"str": "JD"}}]