Zepruv › Coding problems

Minimum Insertion Steps to Make a String Palindrome

Hard · String, Dynamic Programming

Given a string s. In one step you can insert any character at any index of the string.
Return the minimum number of steps to make s palindrome.
A Palindrome String is one that reads the same backward as well as forward.

Example 1

Input: s = "zzazz"
Output: 0

The string "zzazz" is already palindrome we do not need any insertions.

Example 2

Input: s = "mbadm"
Output: 2

String can be "mbdadbm" or "mdbabdm".

Example 3

Input: s = "leetcode"
Output: 5

Inserting 5 characters the string becomes "leetcodocteel".

Constraints

Starter code (python)

class Solution(object):
    def minInsertions(self, s):
        """
        :type s: str
        :rtype: int
        """
        

Related problems

Previous: All Elements in Two Binary Search Trees · Next: Convert Integer to the Sum of Two No-Zero Integers · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.