DatabricksOA #21
Longest Common Prefix of Number Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)Trie & CodecHashing
Given two arrays of positive integers, take one number from each and find the maximum, over all pairs, of the length of the longest common prefix of their decimal representations; if no pair shares a first digit, output 0.
Standard input/output and this site's supplementary ranges follow this problem's description.
Input
The first line contains n m (1≤n,m≤50000), followed by two lines giving n and m integers respectively, all in [1,10⁹]. The range of m is a site supplement, following the original limit given for the first array.
Output
Output the maximum length of the longest common prefix, as one integer.
Example 1
Input:
6 7
25 288 2655 54546 54 555
2 255 266 244 26 5 54547
Output:
4
Example 2
Input:
6 7
25 288 2655 544 54 555
2 255 266 244 26 5 5444444
Output:
3
Example 3
Input:
2 2
817 99
1999 1909
Output:
0
Editorial
Loading solution…