1class Solution {2public:3int reductionOperations(vector<int> &nums) {4int n = nums.size();56map<int, int> mp;7for (int i = 0; i < n; i++) {8mp[nums[i]]++; // storing the frequency9}1011int ans = 0;12int pre = 0;13for (auto i = mp.end(); i != mp.begin(); i--) {14ans += i->second + pre; // total operations15pre += i->second; // maintaing the previous frequency count16}17return ans;18}19};