(C++) 0ms Easy and Simple O(n)
\nclass Solution {\npublic:\n    string breakPalindrome(string p) {\n        if(p.size()==1)\n        {\n            return "";\n        }\n        int a=0;\n  
```\nclass Solution {\npublic:\n    string breakPalindrome(string p) {\n        if(p.size()==1)\n        {\n            return "";\n        }\n        int a=0;\n        for(char x: p)\n        {\n            if(x==\'a\') a++;\n        }\n        if(a==p.size())\n            p[p.size()-1]=\'b\';\n        else if(a==p.size()-1 && p.size()&1)\n        {\n            if(p[p.size()/2]!=\'a\')\n                p[p.size()-1]=\'b\';\n        }\n        else\n        {\n            for(int i=0;i<p.size()/2+1;i++)\n            {\n                if(p[i]!=\'a\')\n                {\n                    p[i]=\'a\';\n                    break;\n                }\n            }\n        }\n        return p;\n    }\n};\n```\nOptimised way for the above approach is to only iterate half of the string and check for character other than \'a\'.\n```\nclass Solution {\npublic:\n    string breakPalindrome(string palindrome) {\n        if(palindrome.size()==1)\n        {\n            return "";\n        }\n        for(int i=0;i<palindrome.size()/2;i++)\n        {\n            if(palindrome[i]!=\'a\')\n               {\n                   palindrome[i]=\'a\';\n                   return palindrome;\n               }\n        }\n        palindrome[palindrome.size()-1]=\'b\';\n        return palindrome;\n    }\n};\n```
['C']