cswork / OA打开练习工作台

CoinbaseOA #1

Find the Length of the Longest Common Prefix

估计中等可在线判题

考点(AI 标注)字典树序列化哈希计数

Choose one positive integer from each of the two arrays and compare the common prefix of their usual decimal representations; return the maximum prefix length over all cross-array pairs, or 0 if no pair shares a first digit.

输入格式

The first line contains n m, the second line contains n numbers, and the third line contains m numbers. Original bounds: 1≤n,m≤50000, 1≤value≤100000000; the largest value has 9 digits.

输出格式

Output a single integer, the answer.

样例 1

输入:

3 1
1 10 100
1000

输出:

3

样例 2

输入:

3 3
1 2 3
4 4 4

输出:

0

样例 3

输入:

1 1
100000000
100000000

输出:

9

样例说明

The outputs of the three public examples are, in order: 3; 0; 9. Verified by independent enumeration or direct simulation.