Problems > Minimum Insertions to Palindrome

Minimum Insertions to Palindrome

Difficulty: 1700 6000 ms 128 MB

strings dp interval-dp

Find the minimum number of characters to insert anywhere in S to make it a palindrome.

Input: one line: the string.

Output: the minimum insertions.

Constraints:

  • 1 ≤ |S| ≤ 2000

Sample Tests

Input 1
ab
Output 1
1
Input 2
aa
Output 2
0
Input 3
abcba
Output 3
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.