QUARANTINE FUN SOLUTIONS QFUN

QUARANTINE FUN SOLUTION

Cook and Abhishek both are battling for the post of Chairperson to be important for ACE board and are attempting their best. To choose just a single understudy their educator gave them a double (string comprising of just 0’s and 1’s) and solicited them to discover number from sub-strings present in the given string that fulfill the accompanying condition: 

The substring should begin with 0 and end with 1 or the substring should begin with 1 and end with 0 however not start with 0 and end with 0 and start with 1 and end with 1. All the more officially, strings, for example, 100,0101 are permitted since they start and end with various characters. In any case, strings, for example, 0110,1101 are not permitted in light of the fact that they start and end with same characters. 

Both Chef and Abhishek attempt their best to comprehend it yet couldn’t do it. You being an awesome companion of Chef, he requests your assistance with the goal that he can tackle it and become the Chairperson. 

 

Info: 

The primary line of the information contains a solitary whole number T signifying the quantity of experiments. The portrayal of T experiments follows. The principal line of each experiment contains a solitary number N signifying the length of the string. The second line of each experiment contains a twofold line of length N. 

 

Yield: 

For each experiment, print a solitary line containing one whole number ― the quantity of sub strings fulfilling above conditions. 

 

Limitations 

1≤T≤1000 

2≤N≤109

Parallel string comprise’s just 0 and 1. 

 

Test Input: 

1010 

 

Test Output: 

 

Clarification: 

All conceivable substring are : { (1),(0),(1),(0),(10),(01),(10),(101),(010),(1010) }. Out of these lone 4 substrings {(10),(01),(10),(1010)} start and end with various characters. Subsequently the appropriate response 4.

DOWNLOAD THE SOLUTION

Leave a Comment