Marks :10
: 8 | : 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.
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$$$.
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.
4 flower flow flight flatter
2
3 dog racecar car
0
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.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.