A backup system inspects a set of filenames (each a string of lowercase English letters) to detect a shared trailing extension pattern. Compute the length of the longest common suffix of all n names: the largest L such that the last L characters of every name are identical. If they share no trailing character, the answer is 0.
Line 1: an integer n, the number of names.
Next n lines: one name per line, each a non-empty string of lowercase English letters.
A single integer: the length of the longest common suffix of all n names.
a-z).Example 1
Input
3 testing running jogging
Expected
3
Explanation
All three end with 'ing' but differ before it, so the common suffix length is 3.
Example 2
Input
2 cat dog
Expected
0
Explanation
They differ at the last character, so the common suffix length is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →