Minimum deletions required to make frequency of each letter unique (HELPPP)

Can anyone please explain me the approach of this problem …??

The article content has been removed. Can you please paste the code here?

The Gfg article has been deleted. So I am providing my own approach here. Hope it helps.

So, you are given a string. First store frequency of each unique character in the string using a map or a frequency array of size 26. Now sort and iterate it from higher frequency. If any of the characters has same frequency in the map, start decrementing the number of characters and incrementing the number of character having frequency-1.
Maintain a counter variable, and count in every increment of decrement.

Hey ,
I used a set to do it cannot access the GFG article which you sent
Pls like :slightly_smiling_face:

import java.util.*;
import java.lang.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
		// your code goes here
		Scanner sc = new Scanner (;
		    String str =;
		    Set<Character> set = new LinkedHashSet<Character>(); // UNORDERED SET
		    for(int i=0;i<str.length();i++)

The problem asked is to find minimum number of deletions. Your code just prints the unique characters in the string

Hey so what you can do is

This way you get minimum number of deletions

public int mindeletion(String S) {
Map<Character,Integer> map = new HashMap<>();
for (int i = 0 ; i < S.length(); ++i) {
char c = S.charAt(i);
int count = 0;
PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); ;

    for (Map.Entry<Character,Integer> entry : map.entrySet())
       pq.add( entry.getValue());

    while (pq.size() != 0) {
        int most_frequent = pq.poll();
        if (pq.size() == 0 ) { return count; }

        if (most_frequent == pq.peek()) {
            if (most_frequent > 1) {
                pq.add(most_frequent - 1);
    return count;