Easy Java Solution- 100% fast with explanation
There are three test cases which helped me for arriving at solution\n1. abccba - Here we are replacing it to aaccba. This should be lexographically small, hence
There are three test cases which helped me for arriving at solution\n1. abccba - Here we are replacing it to aaccba. This should be lexographically small, hence we have to search for first non occurence of a and replace it with \'a\'. \n2. aaabaaa - Here it will be replaced as aaabaab which will be the lexographically small string. Here we replace end of the string with next smaller alphabet after \'a\' which will be \'b\'.\n3. a/b/c - These cannot be made as non-pallindrome, hence return empty string.\n```\nclass Solution {\n    public String breakPalindrome(String palindrome) {\n        if(palindrome.length() <= 1) return new String();\n        int n = palindrome.length();\n        StringBuilder sb = new StringBuilder(palindrome);\n        for(int i=0; i<n/2; i++){\n            if(palindrome.charAt(i)!=\'a\'){\n              sb.setCharAt(i , \'a\');\n               return sb.toString();\n            }\n        }\n        sb.setCharAt(n-1 , \'b\');\n        return sb.toString();\n    }\n}\n```
['Java']