C++ || Sorting
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n generating expected string "s1" by sorying original string\n comparing a
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* generating expected string "s1" by sorying original string\n* comparing and swapping charcters if expected string and original string do not match\n\n```\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        string expected_s=s;\n        sort(expected_s.begin(),expected_s.end()); \n        \n        long long c=0;\n        int n=s.length();\n        \n        int i=0, j=n-1;\n        while(i<=j){\n            while(j>=i && s[j]==s1[j]) j--;\n            \n            if(s[i] != expected_s[i]){\n                swap(s[i],s[j]);\n                c += (j-i);\n            }else{\n                i++;\n            }\n        }\n        \n        return c;\n    }\n};\n```\n\n**Do upvote if it helps :)**
[]