2-D Dynamic Programming Two strings
568. Minimum Insertion Steps to Make a String Palindrome
You are given a string s. In one step you may insert any lowercase letter at any position of s: at the
start, at the end, or between two letters. Return the fewest steps that turn s into a palindrome.
A palindrome reads the same forwards and backwards, such as "noon" or "refer". The letters already in
s stay in their order, and none can be removed.
Example 1
Input: s = "genie"
2Explanation: Insert an n after the i and a g at the end. That gives genineg, which reads the same both ways. One
insertion is not enough.
Example 2
Input: s = "kayak"
0Explanation: The string is already a palindrome, so no step is needed.
Example 3
Input: s = "dog"
2Explanation: No letter repeats, so only one letter can stay unpaired in the middle. dogod adds a partner for the d
and for the o.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length ≤ 3000sholds only lowercase English letters.
Clarifying questions
What you would ask an interviewer before writing any code.