Game with String
Submissions: 5631   Accuracy:

35.13%

  Difficulty: Easy   Marks: 2

Given a string 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:
Input :
str = abccc, K = 1
Output : 6
We remove c to get the value as 11 + 11 + 22

Input:
First line consists of T test cases. First line of every test case consists of String s. Second line of every test case consists of a integer K.

Output:
Single line output, Print the minimum square sum.

Constraints:
1<=T<=100
1<=|String length|<=100

Example:
Input:

2
abccc
1
abccc
2
Output:
6
3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.