BETA

Difficulty Level:

Basic

Total Submissions: 3316 Accuracy:

19.78%

Longest Common Prefix in an Array
       

Given a array of n strings, find the longest common prefix among all strings present in the array.

Input:
The first line of the input contains an integer T which denotes the number of test cases to follow. Each test case contains an integer n. Next line has space separated n strings. 

Output:
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).

Constraints:
1<=T<=200
1<=n<=100
1<=|S|<=100

Example:
Input:

2
4
geeksforgeeks geeks geek geezer
3
apple ape april

Output:
gee
ap

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

Contributor: Shashwat Jain

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.