Intuition
We can run a basic palindrome checker, but to get a lexicographically smaller string, it’s crucial that while building a palindrome - we select the lexicographically smaller character amongst s[left]
and s[right]
.
A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we would be visiting all characters in the string of length N.
-
Memory
The memory usage is since we are converting the input string
s
to a listv
.
— A