String protocol solution codechef – An input string SS of length NN is transferred through the network using a special protocol. The protocol can send the string through a series of operations

String protocol solution codechef

An input string SS of length NN is transferred through the network using a special protocol. The protocol can send the string through a series of operations. In one operation, we can choose a lowercase english alphabet CC and do one of the following:

  • Transfer 11 copy of CC through the network.
  • Transfer 22 copies of CC through the network.

Each of the above transfers take 11 unit of time.

Find the minimum time in which we can transfer the entire string SS through the network.

Input Format

  • The first line will contain TT – the number of test cases. Then the test cases follow.
  • First line of each test case contains NN – the length of the string SS.
  • Second line of each test case contains the string SS.

Output Format String protocol solution codechef

For each test case, output in a single line, the minimum time required to transfer the string.

Constraints

  • 1T1001≤T≤100
  • 1N1051≤N≤105
  • Sum of NN over all test cases does not exceed 105105.
  • String SS contains lowercase english alphabets only.

Sample Input 1  String protocol solution codechef

2
5
cbcdc
6
aabeee

Sample Output 1 

5
4

Explanation String protocol solution codechef

Test Case 11: String can be transferred through following operations: send 11 copy of character cc, send 11 copy of character bb, send 11 copy of character cc, send 11 copy of character dd, and send 11 copy of character cc. Thus, total 55 operations are required.

Test Case 22: String can be transferred through following operations: send 22 copies of character aa, send 11 copy of character bb, send 11 copy of character ee, and send 22 copies of character ee. Thus, total 44 operations are required

For Solution

Click Here

Leave a Comment