Loading Now

smallestPalindrome

Given a string s find the lexicographically smallest palindrome of the same length that is lexicographically greater than or equal to s.

Strings may contain only lowercase English letters.

Example

  • For s = "cbaba", the output should be smallestPalindrome(s) = "cbabc";
  • For s = "abcbc", the output should be smallestPalindrome(s) = "abdba".

Input/Output

  • [execution time limit] 2 seconds

  • [input] string s

    A string containing only lowercase English letters.

    Guaranteed constraints:
    4 ≤ s.length ≤ 5 · 105.

  • [output] string

    The required palindrome.

Post Comment

Contact