AlgoUniversity
  • Go Back
Discussion
Smart Dictionary :

Author

Ayush Gangwani

Difficulty Level : Easy

Submissions : 190

Asked In : Nagarro

Marks :10

: 9 | : 0

Given a list of $$$N$$$ strings, find the length of the longest common prefix of all the strings.

The longest common prefix of a list of strings is the longest string $$$S$$$ which is the prefix of all the strings in the array.

For example, if the list of strings is $$$\{$$$"this,"that","there"$$$\}$$$, the longest common prefix is "th" as it is the longest string which is the prefix of all the strings.

Input

The first line of input contains an integer $$$N$$$ — the number of strings.

The next $$$N$$$ lines contain a string each, denoting the strings in the list.

The strings consists of lowercase latin letters and the sum of length of strings doesn't exceed $$$10^6$$$.

Output

Print a single integer — the length of the longest common prefix of the list of strings. If the strings do not have a common prefix, print 0.

Examples

Input
4
flower
flow
flight
flatter
Output
2
Input
3
dog
racecar
car
Output
0

Note

In test case 1, the longest common prefix of the given list of strings is "fl" and hence the output is 2.

In test case 2, the given list of strings do not share any common prefix and hence the output is 0.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.