Problem title
Difficulty
Avg time to solve

Factorial Of Large Number
Moderate
30 mins
Count Subarrays with Given XOR
Moderate
15 mins
Cooking Ninjas
Moderate
25 mins
Set Bits
Easy
--
N Stacks In An Array
Hard
20 mins
All substrings
Easy
--
Longest Common Prefix
Moderate
40 mins
Remove Duplicates From Sorted List
Easy
--
Minimum Elements
Moderate
40 mins
Nth Fibonacci Number
Easy
--
29

# Longest Common Prefix

Difficulty: MEDIUM
Contributed By
Avg. time to solve
40 min
Success Rate
60%

Problem Statement

#### A prefix of a string can be defined as a substring obtained after removing some or all characters from the end of the string.

##### For Example:
``````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”.
``````
##### Input Format:
``````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’.
``````
##### Output Format:
``````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.
``````
##### Note:
``````You do not need to print anything. It has already been taken care of. Just implement the given function.
``````
##### Constraints:
``````1 <= T <= 10
1 <= N <= 3000
1 <= |ARR[i]| <=1000

Each string consists of only lowercase letters.

Time limit: 1 sec
``````
##### Sample Input 1:
``````2
4
coding codezen codingninja coder
3
night ninja nil
``````
##### Sample Output 1:
``````cod
ni
``````
##### Explanation of sample input 1:
``````For the first test case,
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”.

For the second test case,
The longest common prefix among all the given strings is “ni” as it is present as a prefix in all strings. Hence, the answer is “ni”.
``````
##### Sample Input 2:
``````2
3
applejuice applepie apple
4
car cus cart carat
``````
##### Sample Output 2:
``````apple
c
``````
Console