C++||Simple Logic Keep Track of Position of 'a'
\nclass Solution {\npublic:\n    string smallestString(string s) {\n        vector<int> pos;\n        int n=s.size();\n        \n        char c=\'a\';\n        
```\nclass Solution {\npublic:\n    string smallestString(string s) {\n        vector<int> pos;\n        int n=s.size();\n        \n        char c=\'a\';\n        vector<char> m(26,\'#\');\n        for(int i=0;i<26;i++)\n        {\n            m[i]=c;\n            c++;\n        }\n        if(n==1)\n        {\n            if(s[0]==\'a\')\n                return "z";\n            char c1=m[(s[0]-\'a\'-1)%26];\n            string s1="";\n            s1.push_back(c1);\n            return s1;\n        }\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]==\'a\')\n                pos.push_back(i);\n        }\n        if(pos.size()==0)\n        {\n           for(int i=0;i<n;i++)\n        {\n            s[i]=m[(s[i]-\'a\'-1)%26];\n        } \n            return s;\n        }\n        if(pos.size()==n)\n        {\n            s[n-1]=\'z\';\n            return s;\n        }\n        for(int i=0;i<pos[0];i++)\n        {\n            s[i]=m[(s[i]-\'a\'-1)%26];\n        }\n        if(pos[0]>0)\n            return s;\n        int sz=pos.size();\n        for(int i=0;i<pos.size()-1;i++)\n        {\n            bool flag=false;\n            for(int j=pos[i]+1;j<pos[i+1];j++)\n           {\n               s[j]=m[(s[j]-\'a\'-1)%26];\n                flag=true;\n           }\n            if(flag)\n            return s;\n        }\n        for(int k=pos[sz-1]+1;k<n;k++)\n        {\n            s[k]=m[(s[k]-\'a\'-1)%26];\n        }\n        return s;\n    }\n};\n```
[]