Longest repeating and non-overlapping substring
Submissions: 1058   Accuracy:

28.98%

  Difficulty: Medium   Marks: 4

Given a string str, find the longest repeating non-overlapping substring in it. In other words find 2 identical substrings of maximum length which do not overlap. If there exists more than one such substring return any of them.

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of the string str.

The second line of each test case contains the string str.It consists of only lower case english alphabets.

Output:

Print the longest non - overlapping substring for each test case in a new line. If no such sub - sequence exists print -1.


Constraints:

1<= T<=100

1<= N <=1000


Example:

Input:

1

13

geeksforgeeks

Output:

geeks

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

Contributor: Sujnesh Mishra
Author: sujnesh


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.