Easy C++ solution O(n) with line by line explanation
Sorting can move smaller digits to the left and greater digits to the right\n\nSo we can always move a digit to the left until we encounter any digit smaller th
Sorting can move smaller digits to the left and greater digits to the right\n\nSo we can always move a digit to the left until we encounter any digit smaller than that.\nSo the solution approach is to create 10 queue for each digit which store indices of digits in S and after that check if any smaller digit is there in front of the digit we are checking\n\n```\nclass Solution {\npublic:\n    bool isTransformable(string s, string t) {\n        \n        int n = s.size();   //size of the string\n        vector<queue<int>> v(10);  //created 10 queue\n\t\t\n        for(int i=0;i<n;i++){       //with this loop inserted all indices of digits in s in queue\n            v[s[i]-\'0\'].push(i);\n        }\n        \n        for(int i=0;i<n;i++){    //loop to traverse string t\n            int k = t[i] - \'0\';\n            if(!v[k].size()) return false;    //if for a particular digit in t we cannot find it in s return false\n\t\t\t\n            for(int j=0;j<k;j++){       //Now for that digit(k) we check in s if any smaller no comes before it if found(any j) \n\t\t\t                                    // we cannot move K in front of that(j) so return false\n                if(v[j].size() && v[j].front()<v[k].front())   //so checking that no less than K don\'t have indices before K\n                    return false;\n            }\n            v[k].pop();  //if everything fine just remove that occurence of K\n        }\n        \n        \n        return true;\n        \n    }\n};\n\n```\n\n
[]