🚀Frequency Mapping Approach🔥(in 2 steps) | ✅0ms | C++
Mapping the frequency of each character in the array.\n(We can also create a map for this frequency mapping)\n\nafter that there are only 2 simple steps, \n\n1-
Mapping the frequency of each character in the array.\n(We can also create a map for this frequency mapping)\n\nafter that there are only 2 simple steps, \n\n1- take all characters in ascending order\n2- take all characters in descending order\n\nthis is how in 2 steps we achieve the logic.\n\n\n# Code\n```\nclass Solution {\npublic:\n    string sortString(string s) {\n        string result = "";\n        int freq[26] = {0};\n\n        for(int i = 0; i < s.length(); i++)\n        {\n            freq[s[i] - 97]++;\n        }\n\n        int n = s.length();\n\n        while(n != 0)\n        {\n            for(int i = 0; i < 26; i++)\n            {\n                if(freq[i] >= 1)\n                {\n                    result += (char)(97 + i);\n                    n--;\n                    freq[i]--;\n                }\n            }\n            for(int i = 25; i >= 0; i--)\n            {\n                if(freq[i] >= 1)\n                {\n                    result += (char)(97 + i);\n                    n--;\n                    freq[i]--;\n                }\n            }\n        }\n\n        return result;\n    }\n};\n```
['Hash Table', 'String', 'Counting', 'C++']