Aye Aye TopCodar

0

0 votes
Basics of String Manipulation
Problem

Ashutosh is very fond of strings and he likes solving problems that involve strings.
His friend Swaraj came up with a question that he recently read in a blog. Swaraj knows that Ashutosh is very fond of strings, so he gave Ashutosh the question he read in the blog. Ashutosh might lose his title of "topCodar" if he can not solve the problem, so he needs your help. Help Ashutosh solve the problem.

Given a string S, of length N consisting of only lowercase English Alphabets. You need to find a string X that has no instances of three identical consecutive letters by removing some or possibly zero characters from string S. Find the longest string X that can be obtained i.e you need to make a minimum number of deletions from S.

Input Format:
 First-line contains T, the number of test cases. 1<=T<=26
 The first line of each test case consists of a number N, length of the string. 1<=N<= 2*10^5
 the second line of each test case contains the string S.

Output Format:
For each test case, print a number n, the length of X, and the string X in a new line.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?