Reported August 2026
Capital Onehash table

Longest Common Prefix of Number Pairs

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

The mistake that sinks most first attempts at this Capital One question is comparing every pair across two arrays of 50000 numbers. That's 2.5 billion comparisons and it times out. Capital One candidates reported this one in August 2026, and the real answer is a prefix set, not dynamic programming despite the hint. Put every prefix of every number from arr1 into a hash set, then walk arr2 and find the longest prefix of each number that's in the set. If you blank on the OA, StealthCoder runs invisibly as a safety net and hands you the approach while you keep typing.

The problem

You are given two arrays of positive integers, arr1 and arr2.
The common prefix of two integers is the longest sequence of decimal digits they share starting from the leftmost digit. For example, 54546 and 54547 have the common prefix 5454, whose length is 4.
Choose one integer from arr1 and one integer from arr2. Return the maximum common-prefix length over all such cross-array pairs. Return 0 if no pair shares its first digit.

Function
longestCommonPrefixLength(arr1: int[], arr2: int[]) → int

Examples
Example 1
arr1 = [25,288,2655,54546,54,555]
arr2 = [2,255,266,244,26,5,54547]
return = 4
54546 and 54547 share the four-digit prefix 5454. No cross-array pair shares a longer prefix.
Example 2
arr1 = [25,288,2655,544,54,555]
arr2 = [2,255,266,244,26,5,5444444]
return = 3
The complete value 544 is a three-digit prefix of 5444444.
Example 3
arr1 = [817,99]
arr2 = [1999,1909]
return = 0
No cross-array pair shares its first digit.

Constraints
The length of each input array is between 1 and 50000, inclusive.
Every array value is between 1 and 1000000000, inclusive.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that a prefix of a number is just its digits cut short, and each number has at most 10 digits since values top out at 1000000000. So arr1 contributes at most 500000 prefixes. Store them in a set, either as integers (repeatedly divide by 10) or as strings. Then for each number in arr2, check its prefixes from longest to shortest and stop at the first hit, tracking the global max length. The common pitfall is the brute-force pair loop, which is O(n*m). A second pitfall is forgetting that a whole number counts as a prefix of a longer one, as in example 2 where 544 is a prefix of 5444444. Dividing by 10 handles that naturally. Track length as the digit count of the matched prefix. Total work is about 10 times n plus 10 times m. If the set idea doesn't come to you under pressure, StealthCoder is the hedge on the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Longest Common Prefix of Number Pairs cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as find the length of the longest common prefix. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Common Prefix of Number Pairs FAQ

What's the trick to Longest Common Prefix of Number Pairs?+

Store all prefixes of arr1 numbers in a hash set, then check prefixes of each arr2 number against it. Each number has at most 10 digits, so total work is tiny. Avoid the nested pair loop, because 50000 times 50000 will time out.

Is this really dynamic programming?+

No. The hinted pattern doesn't fit. There are no overlapping subproblems. It's a hash set of prefixes, with a trie as an alternative. Treat it as a hash-table problem and you'll finish faster and with cleaner code.

Should I use a trie or a hash set?+

Either works. A hash set of integer prefixes is shorter to write: divide by 10 in a loop and insert each value. A trie over digits is fine too and gives the same complexity. In a timed OA, pick the hash set for less code and fewer bugs.

How do I get the prefix length from an integer?+

Track it as you go. For a number with d digits, its first prefix has length d, then d-1 after dividing by 10, and so on. Or convert to a string and use slices. When you find a match in the set, the length is the current digit count, and you keep the max.

How do I prepare for this in 48 hours?+

Write the hash set solution once from scratch. Test it against the three examples, especially example 3 returning 0 and example 2 where a whole number is a prefix. Know the complexity: roughly 10 times (n+m). That's enough for this Capital One question.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it