#K14271. Longest Common Prefix Length

    ID: 24098 Type: Default 1000ms 256MiB

Longest Common Prefix Length

Longest Common Prefix Length

You are given several test cases. In each test case, you are provided with a list of strings. Your task is to compute the length of the longest common prefix among these strings.

The longest common prefix is defined as the longest substring that appears at the beginning of every string in the list. If there is no such common prefix, the answer is 0.

For example, for the strings "flower", "flow", and "flight", the longest common prefix is "fl", whose length is 2.

Input/Output

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N1
s1
s2
... 
sN1
N2
s1
s2
... 
sN2
...
NT
s1
s2
... 
sNT

Where:

  • T is the number of test cases.
  • For each test case, the first line contains an integer N, the number of strings.
  • Then follows N lines each containing a single string.

outputFormat

For each test case, output a single integer on a new line indicating the length of the longest common prefix among the given strings.

The output is written to standard output (stdout).

## sample
4
3
flower
flow
flight
3
dog
racecar
car
1
single
3
abcdefg
ab
abc
2

0 6 2

</p>