A lab stores short symbol sequences that are supposed to read the same forwards and backwards. A transmission glitch dropped some symbols, leaving the sequence incomplete.
To repair it, you may insert symbols anywhere in the string. You can insert any characters as many times as needed. Determine the minimum number of insertions required to make the string a palindrome.
A palindrome is a string that reads the same from left to right and right to left.
Input
s = "ab"
Output
1
Explanation
One possible repair is inserting 'a' at the end to form "aba". Another possible repair is inserting 'b' at the front to form "bab". Both require only one insertion.
Input
s = "mbadm"
Output
2
Explanation
The string can be transformed into "mbdadbm" by inserting two characters. Therefore, the minimum number of insertions required is 2.
The input contains a single string s.
Return a single integer representing the minimum number of character insertions required to make s a palindrome.
0 ≤ len(s) ≤ 2000s consists only of lowercase English letters.ab
1
int minInsertions(string s)
Return
Return an integer representing the minimum number of insertions required to make the given string a palindrome.
Nutanix • Pending
Nutanix • Pending
OYO (Prism) • Pending
OYO (Prism) • Pending