Loading Now

buildPalindrome

palindrome is a string that reads the same left-to-right and right-to-left.

Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome.

Example

  • For str = "abcdc", the output should be buildPalindrome(st) = "abcdcba".
  • For str = "abc", the output should be buildPalindrome(st) = "abcba".
  • For str = "abba", the output should be buildPalindrome(st) = "abba".

Input/Output

  • [execution time limit] 0.5 seconds

  • [input] string st

    A string consisting of lowercase English letters.

    Guaranteed constraints:
    3 ≤ st.length ≤ 10000.

  • [output] string

Post Comment

Contact