From 3f29c3729fe9688063c5b88386ac874eb150e542 Mon Sep 17 00:00:00 2001 From: chayan das Date: Sun, 22 Jun 2025 08:27:52 +0530 Subject: [PATCH] Create 3085. Minimum Deletions to Make String K-Special --- ...Minimum Deletions to Make String K-Special | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 3085. Minimum Deletions to Make String K-Special diff --git a/3085. Minimum Deletions to Make String K-Special b/3085. Minimum Deletions to Make String K-Special new file mode 100644 index 0000000..a164e51 --- /dev/null +++ b/3085. Minimum Deletions to Make String K-Special @@ -0,0 +1,36 @@ +class Solution { +public: + int minimumDeletions(string word, int k) { + unordered_map freq; + for(auto x:word){ + freq[x]++; + } + vector storage; + for(auto pair: freq){ + storage.push_back(pair.second); + } + sort(storage.begin(),storage.end()); + int n=storage.size(); + //now we need to check that how many deletion would be needed to make the freq lie in the range of [reference,reference+k] --> so that difference of freq is at most k. +int min_times=1e5; + // for each freq considering it as reference and calcualating deletion + for(int i=0;iref+k){ + deletion+=storage[j]-(ref+k); + } + } + if(deletion