Consider ARR = [“coding”, ”codezen”, ”codingninja”, ”coders”]
The longest common prefix among all the given strings is “cod” as it is present as a prefix in all strings. Hence, the answer is “cod”.
The first line of the input contains a single integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer ‘N’ denoting the number of strings in the array.
The next line contains ‘N’ space-separated strings denoting the elements of the array ‘ARR’.
For each test case, print a single string corresponding to the longest common prefix.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 3000
1 <= |ARR[i]| <=1000
Each string consists of only lowercase letters.
Time limit: 1 sec
Batteries
Find The Single Element
Find minimum
Search In A Sorted 2D Matrix
Fake Coin Problem