title: Dynamic Programming Set 28 Minimum Insertions To Form A Palindrome
signature: def dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, l, h):
test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(str, l, h, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              str, l, h),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver(['F', 'F', 'J', 'K', 'K', 'L', 'P', 'S', 'T', 'V', 'W', 'Y', 'b', 'd', 'j', 'l', 't', 'u', 'x', 'y'], 11, 11, 0)
      print(f"TEST-0...{result}")
  
      result = driver(['0', '1', '8', '8', '8', '4', '4', '3', '9', '6', '5', '2', '8', '2', '0', '2', '6', '0', '7', '7', '3', '2', '4', '5', '9', '7', '2', '4', '1', '8', '7', '9', '8', '0', '8', '5', '4', '2', '3'], 19, 22, 3)
      print(f"TEST-1...{result}")
  
      result = driver(['1'], 0, 0, 0)
      print(f"TEST-2...{result}")
  
      result = driver(['g', 'y', 'r', 'M', 'v', 'z', ' ', 'k', 'S', 'P', 'x', 'p', 'E', 'z', 'T', 'K', 'k', 'B', 's', 'P', 'p', 'e', 'G', 't', 'r', 'M', 'p', ' ', 'H', 'a'], 24, 27, 3)
      print(f"TEST-3...{result}")
  
      result = driver(['0', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '7', '8', '8', '8', '9', '9'], 33, 34, 0)
      print(f"TEST-4...{result}")
  
      result = driver(['X', 'B', 'E', 'v', 'K', 't', 'k', 'K', 'Q', 's', 'V', 'N', 'l', 'k', 'T', 'N', 'J', 'z', 'f', 'p', 'J', 'g', 'S', 'P', 'M', 'b', 'H', 'L', 'v', 'E', 'A', 'n', 'D', 'U', 'c', 's', 'M', 'Q', 'P', 'g', 'g', ' '], 26, 27, 1)
      print(f"TEST-5...{result}")
  
      sys.exit(0)
source_py: def dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, l, h):
      if (l > h):
          return sys.maxsize
      if (l == h):
          return 0
      if (l == (h - 1)):
          return (0 if (str[l] == str[h]) else 1)
      if (str[l] == str[h]):
          return dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, (l + 1), (h - 1))
      else:
          return (min(dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, l, (h - 1)), dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, (l + 1), h)) + 1)
source_cpp: int dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(vector<char> str, int l, int h) {
    if ( l > h ) return INT_MAX;
    if ( l == h ) return 0;
    if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1;
    return ( str [ l ] == str [ h ] ) ? dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l + 1, h - 1 ) : ( min ( dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l, h - 1 ), dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l + 1, h ) ) + 1 );
  }