Brute Force With Explanation || JAVA
\n\tclass Solution {\n        public String smallestString(String s) {\n             StringBuilder sb = new StringBuilder();\n             boolean f = true;\n  
\n\tclass Solution {\n        public String smallestString(String s) {\n             StringBuilder sb = new StringBuilder();\n             boolean f = true;\n             int i = 0;\n             while(i < s.length()){\n                if(s.charAt(i) == \'a\') {      // When a encountered\n                    sb.append(\'a\');       // Append a in answer\n                    i++;\n                    if(f) {       // f=true means till now no operation is performed\n                         while(i < s.length() && s.charAt(i) == \'a\') {   // append all a which makes lexicographically smaller string\n                            sb.append(\'a\');\n                            i++;\n                          }\n                         while(i < s.length()) {   // Loop remaining string if any\n                            if(s.charAt(i) == \'a\') {       // at that point we already done with the operation simply add remaining string to answer\n                                while(i < s.length()) {\n                                   sb.append(s.charAt(i));\n                                         i++;     }\n                                 }\n                             else{          // else append the substring ch-1 to answer until next a encountered\n                                sb.append((char)(\'a\'+(s.charAt(i)-\'a\')-1));  \n                                f = false;\n                              }\n                          i++;     }\n                         }\n                      else{\n                         while(i < s.length()) {     // append remaining ch to answer when f becomes false i.e atmost one operation is already performed\n                             sb.append(s.charAt(i));\n                             i++;      }\n                     }\n               }\n                 else{    // Simply append until first a encountered\n                    sb.append((char)(\'a\' + (s.charAt(i) - \'a\') - 1 ));\n                    f = false;   }\n                i++;\n            }\n            if(f){       // if no operation performed till now check last ch and perform operation\n                 if(sb.charAt(sb.length() - 1) == \'a\') {\n                       sb.setCharAt(sb.length() - 1, \'z\');\n                  }\n                 else{\n                      sb.setCharAt(sb.length() - 1, (char)(\'a\' + (sb.charAt(sb.length() - 1) - \'a\') -1));\n                   }\n              }\n            return sb.toString();\n          }\n      }
['Java']