1
class Solution {
2
public:
3
int reductionOperations(vector<int> &nums) {
4
int n = nums.size();
5

6
map<int, int> mp;
7
for (int i = 0; i < n; i++) {
8
mp[nums[i]]++; // storing the frequency
9
}
10

11
int ans = 0;
12
int pre = 0;
13
for (auto i = mp.end(); i != mp.begin(); i--) {
14
ans += i->second + pre; // total operations
15
pre += i->second; // maintaing the previous frequency count
16
}
17
return ans;
18
}
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0