Find the Length of the Longest Common Prefix

Medium · Trie · about 20 minutes

Asked at Google, Amazon, Coinbase, Roblox, Databricks, Plaid, Revolut, Cohere, Hugging Face, Kraken.

Given two arrays of positive integers arr1 and arr2, a common prefix of two integers is the longest leading run of digits they share (e.g. 5655359 and 56554 share 565). Return the length of the longest common prefix over all pairs (x, y) with x from arr1 and y from arr2, or 0 if no pair shares one.

Related guides