Skip to content

Commit 5ef07a9

Browse files
committed
Solution as on 03-07-2022 08:00 am
1 parent e6d94c6 commit 5ef07a9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// 1647.✅ Minimum Deletions to Make Character Frequencies Unique
2+
3+
class Solution
4+
{
5+
public:
6+
int minDeletions(string s)
7+
{
8+
vector<int> v(26, 0);
9+
10+
for (auto a : s)
11+
{
12+
++v[a - 'a'];
13+
}
14+
15+
sort(v.begin(), v.end(), greater<int>());
16+
17+
int ans = 0, f = v[0];
18+
19+
for (auto a : v)
20+
{
21+
if (a > f)
22+
{
23+
if (f > 0)
24+
ans += (a - f);
25+
else
26+
ans += a;
27+
}
28+
f = min(f - 1, a - 1);
29+
}
30+
return ans;
31+
}
32+
};

0 commit comments

Comments
 (0)