Game with String
Easy Accuracy: 35.68% Submissions: 7223 Points: 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

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window