C++ Soln || Beats 100% 🔥|| Easy || Comparator || Lambda Function
Intuition\nThe goal of this problem is to sort the elements of the array based on their frequency in ascending order. If two elements have the same frequency, t
# Intuition\nThe goal of this problem is to sort the elements of the array based on their frequency in ascending order. If two elements have the same frequency, they should be sorted by their value in descending order. This ensures that less frequent elements appear earlier, and for elements with the same frequency, the larger values come first.\n\n# Approach\n1)  Frequency Counting: Use an unordered_map to count the frequency of each element in the input vector nums.\n2)  Custom Sorting: Sort the input vector using a custom comparator. The comparator checks the frequency of the elements from the map:\n- If two elements have the same frequency, the comparator returns true if the first element is greater than the second, ensuring larger values come first.\n- If two elements have different frequencies, the comparator returns true if the frequency of the first element is less than the frequency of the second, ensuring lower frequencies come first.\n3)  Return Result: The sorted vector is returned as the result.\n\n# Complexity\n- Time complexity:O(n log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> frequencySort(vector<int>& nums) {\n        unordered_map<int, int> map;\n        for (auto i : nums) {\n            map[i]++;\n        }\n        sort(nums.begin(), nums.end(), [&map](int a, int b) {\n            if (map[a] == map[b]) {\n                return a > b;\n            }\n            return map[a] < map[b];\n        });\n        return nums;\n    }\n};\n\n```
['C++']