Skip to content

Instantly share code, notes, and snippets.

@anmolj7
Created January 15, 2020 03:26
Show Gist options
  • Save anmolj7/19346802c5cb23f62921d74ab72addd5 to your computer and use it in GitHub Desktop.
Save anmolj7/19346802c5cb23f62921d74ab72addd5 to your computer and use it in GitHub Desktop.
'''
Problem
Write a program that reads a string S and find the minimum number r of applications of the function replace(a,b) to form a palindrome.
'''
def main():
String = input() #Isn't displaying any string while taking input because
#if you're using an online judge to check our answers, then, it'd show wrong answer
#because of this.
count = i = 0
j = len(String)-1
while i < j:
#To be honest, I really wanna know who created the convention of using
#i and j as indices... I've gotten so used to it that I can't use any other!
if String[i] != String[j]:
count += 1
String = String.replace(String[i], String[j])
i += 1
j -= 1
print(count)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment