1164. Minimum Insertions to Make String Palindrome

EasyDynamic ProgrammingSequence DP

Given a string s, return the minimum number of characters to insert anywhere so that s becomes a palindrome. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the minimum insertions.

Examples

Example 1
Input: {"s":"mbadm"}
Output: 2
Explanation: Insert two characters.
Example 2
Input: {"s":"leetcode"}
Output: 5
Explanation: Five insertions needed.
Example 3
Input: {"s":"a"}
Output: 0
Explanation: Already a palindrome.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →