main nahi bataunga
bruteCoder
java
a year ago
814 B
7
Indexable
class Solution{ static int minValue(String s, int k){ // code here HashMap<Character,Integer> map = new HashMap<>(); for(char el : s.toCharArray()){ map.put(el,map.getOrDefault(el,0)+1); } PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); for(int el : map.values()){ pq.offer(el); } while(!pq.isEmpty() && k-->0){ int temp = pq.poll(); temp -= 1; if(temp == 0 ) continue; pq.offer(temp); } int out = 0 ; for(int temp : pq){ out += (temp * temp); } return out; } }
Editor is loading...
Leave a Comment