Leetcode 3043. Find the Length of the Longest Common Prefix
Given two arrays of positive integers, return the maximum length (in digits) of a common leftmost-digit prefix shared by any number from arr1 and any number from arr2, or 0 if none exists. The core task is efficiently comparing digit-prefixes across up to 5e4 numbers (digits ≤9), e.g., by converting to strings and using prefix sets, tries, or hashing to find the longest intersecting prefix.
Asked at:
Apple
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early June, 2026
Apple
Mid-level
I got similar question where I was given routes as list of tuples (key, value) pair [("x/y", 4), ("x/y/z/", 1), ("xyz/abc", 2), ("fgh/ijk/lmn", 3)] and then I was given query ["x/y", "fgh/ijk/", "x/y/z/a", "abc/"] and I was asked to return array of values [4, -1, 1, -1]
Mid September, 2024
Apple
Senior
Longest common prefix
Hello Interview Premium
Your account is free and you can post anonymously if you choose.