Please enter your email address or userHandle.
Given a array of N strings, find the longest common prefix among all strings present in the array.
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.
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).
1 <= T <= 103
1 <= N <= 103
1 <= |S| <= 103
geeksforgeeks geeks geek geezer
apple ape april
Testcase 1: Longest common prefix in all the given string is gee.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.