Geeksforgeeks

Error

Given a string **s** of lowercase alphabets and a number k, the task is to print the minimum value of the string after removal of **‘k’** characters. The value of a string is defined as the sum of squares of the count of each distinct character.

**Example 1:**

Input:s = abccc, k = 1Output:6Explaination:We remove c to get the value as 1^{2}+ 1^{2}+ 2^{2}

**Example 2:**

**Input: **s = aabcbcbcabcc, k = 3
**Output:** 27
**Explaination:** We remove two 'c' and one 'b'.
Now we get the value as 3^{2 }+ 3^{2} + 3^{2}.

**Your Task:**

You do not need to read input or print anything. Your task is to complete the function **minValue()** which takes s and k as input parameters and returns the minimum possible required value.

**Expected Time Complexity:** O(N*logN) where N is the length of string

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ k ≤ |string length| ≤ 100

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Game with String

...