[Java] 0 ms Intuitive Code w/ Explanation
1328. Break a Palindrome\n\nclass Solution {\n    public String breakPalindrome(String palindrome) {\n        if(palindrome.length()<=1)\n           return "";\
**1328. Break a Palindrome**\n```\nclass Solution {\n    public String breakPalindrome(String palindrome) {\n        if(palindrome.length()<=1)\n           return "";\n        char[] arr = palindrome.toCharArray();\n        \n        for(int i=0; i<arr.length/2;i++){ \n           if(arr[i] != \'a\'){ // if not a then change it to be lexographically smallest\n               arr[i] = \'a\';\n               return String.valueOf(arr);\n           }\n        }\n        // if we reach here, there are ONLY \'a\' in palindrome string, so we should change the last character to a b\n        arr[arr.length-1] = \'b\';\n        return String.valueOf(arr);\n    }\n}\n```\n**PROBELM OVERVIEW**\nWe are given a palindrome and want to make it the lexicographically *smallest* non-palindrome\n\n**SOLUTION ASSESSMENT**\nThere are one of 2 states:\n* If the characer is not an \'a,\' change it to be an \'a\' to break the palindrome **and** make it lexiographically smaller\n* if all the characters are \'a\' change the last letter to be a \'b\' to break the palindrome, and since it\'s the last letter, increasing it to a \'b\' will **minimize** the increase in lexicographical order.\n\t\n**PROCESS**\nWe do this by converting the string into a char[] array. Note, we only need to iterate until arr.length/2 because it is guaranteed that anything afterwards is a repetition of the characters we have already encountered. Also, arr.length/2 avoids the error of changing the center character in an odd-lengthed string, which has no effect on it.\n\nEX: "aabaa" -> "aaaaa" is still a palindrome **|** therefore, arr.length/2, which is 2, will not reach the middle character. \nEX: "aaaaa" -> "aaaab" is the smallest. We need to change the **LAST non-a** because anything else will be larger ( "aaaba" > "aaaab" in the dictionary) \n\nHopefully this helps. :)
['Java']