CoinbaseOA #1
Find the Length of the Longest Common Prefix
Estimated MediumJudge-ready
Topics (AI-labelled)Trie & CodecHashing
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.
Input
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
Output a single integer, the answer.
Example 1
Input:
3 1
1 10 100
1000
Output:
3
Example 2
Input:
3 3
1 2 3
4 4 4
Output:
0
Example 3
Input:
1 1
100000000
100000000
Output:
9
Example notes
The outputs of the three public examples are, in order: 3; 0; 9. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…