Solution with pictures and notes [JavaScript]
Algorithm\nIn a palindrome, all the characters appear in pairs except for the middle element. To generate lexicographically smallest string, we can select any c
# Algorithm\nIn a palindrome, all the characters appear in pairs except for the middle element. To generate lexicographically smallest string, we can select any character before the middle, and change it to the smallest character, i.e. `a`. So we iterate through the first half of the string. If the character isn\'t already the smallest, we change it to \'a\' and return the new string.\n\nedge case 1: if the length of the string is $1$, then we can never break the string by replacement. So we return `""`.,\n\nedge case 2: if all the characters are already the smallest, i.e. `a`, then we change the last character of the string to the second smallest character available, i.e. `b`.\n\n![break-palindrome.jpeg](https://assets.leetcode.com/users/images/350e6e3d-7044-4b9b-9fc6-e39f59136b0b_1665381611.0712337.jpeg)\n\n# Complexity\nIf there are total $n$ characters in the string -\n\n* Time complexity: $O(n)$. we iterate through the first half, or $(n / 2)$ characters to determine the first character to be replaced. Depending on the language of implementation, string mutation can be $O(1)$ or $O(n)$ operation. So the time complexity is $O(n)$.\n* Space complexity: In the current implementation, we make use of an auxiliary array to replace the corresponding character, so it requires $O(n)$ space. If the replacement is done in place though, then it wouldn\'t \nneed any extra space. (We don\'t count the space reserved only for the output)\n\n# Code\n```\n/**\n * @param {string} palindrome\n * @return {string}\n */\nfunction breakPalindrome(palindrome) {\n  if (palindrome.length === 1) {\n    return "";\n  }\n  let arr = palindrome.split("");\n  for (let i = 0; i <= Math.floor(arr.length / 2) - 1; i++) {\n    if (arr[i] !== \'a\') {\n      arr[i] = \'a\';\n      return arr.join("");\n    }\n  }\n  arr[arr.length - 1] = \'b\';\n  return arr.join("");\n};\n```
['JavaScript']