Beginner-friendly || Simple solution with Two Pointer in Python3 / TypeScript
Intuition\nLet\'s briefly explain what the problem is:\n- there\'s a string s with lowercase English letters\n- our goal is to modify s to be the lexicographica
# Intuition\nLet\'s briefly explain what the problem is:\n- there\'s a string `s` with lowercase English letters\n- our goal is to modify `s` to be **the lexicographically smallest palindrome**\n\n**A palindrome** is a string, when an original word is equal to its **reversed version**.\nThe simplest way to build this palindrome is to set **Two Pointers** opposite to each other, compare particular letters and use **the lexicographically smallest one**.\n\n```\n# Example\n\ns = \'aecab\'\n# i = 0, j = 4 => a < b, (a)eca(a)\n# i = 1, j = 3 => e > a, a(a)c(a)a\n# The lexicographically smallest palindrome is \'aacaa\'\n```\n\n# Approach\n1. declare `ans` to store letters\n2. iterate over **half** of a string with `left` and `right` pointers\n3. check ASCII precedence to find **the lexicographically smallest letter** between `s[left]` and `s[right]`\n4. return `ans` \n\n# Complexity\n- Time complexity: **O(N)** to iterate over `s`\n\n- Space complexity: **O(N)** to store `ans`\n\n# Code in Python3\n```\nclass Solution:\n    def makeSmallestPalindrome(self, s: str) -> str:\n        n = len(s)\n        ans = [\'\'] * n\n        left = 0\n\n        for right in range(n - 1, (n - 1) // 2 - 1, -1):\n            if s[left] <= s[right]:\n                [ans[left], ans[right]] = [s[left], s[left]]\n            else: \n                [ans[left], ans[right]] = [s[right], s[right]] \n            \n            left += 1\n\n        return "".join(ans)\n```\n# Code in TypeScript\n```\nfunction makeSmallestPalindrome(s: string): string {\n    const n = s.length\n    const ans = Array(n).fill(\'\')\n\n    for (let right = n - 1, left = 0; right >= right / 2; right--, left++) {\n        if (s[left] <= s[right]) {\n            ans[left] = s[left]\n            ans[right] = s[left]\n        } else {\n            ans[left] = s[right]\n            ans[right] = s[right]\n        }\n    }\n\n    return ans.join(\'\')\n};\n```
['Two Pointers', 'String', 'TypeScript', 'Python3']