Brute-force approach
Here I present a few approaches to deduce “minimum insertions” required to convert a string into a palindrome.
The basic brute force approach is quite simple, given a string with length L, start comparing, the first character from left and the last character while scanning inwards.
Here is a basic test for a palindrome.
L = len(s)
for i in range(L):
if s[i] != s[L - i - 1]:
return False,i,L-i -1
return True,0,0
The above code returns True if the string is a palindrome or returns False with mismatching indices.