Trains the technique from
LeetCode 3043Find the Length of the Longest Common PrefixThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A courier network stamps every parcel with a numeric routing code, written in decimal with no leading zeros. A code is read from the left: the first digit names the region, the digit after it names a depot inside that region, and so on down to the delivery walk. Two codes therefore travel together for as far as their leading digits agree.
You are given two arrays of routing codes, northern and southern. Take one code from northern and one from southern. Their shared lead is how many digits they agree on, counting from the leftmost digit and stopping at the first position where they differ or where either code runs out of digits.
Return the longest shared lead over every way of pairing one code from northern with one code from southern. If no such pairing agrees on even its leftmost digit, return 0.
Example 1
Pairing 917 with 9174 agrees on the digits 9, 1 and 7, then 9174 still has a digit left while 917 has run out, so that pairing has a shared lead of 3.
Example 2
Every pairing differs at the leftmost digit, so no pairing has a shared lead at all.
Example 3
Pairing 80 with 800 agrees on the digits 8 and 0, and 80 then runs out, giving a shared lead of 2.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_shared_lead(northern: list[int], southern: list[int]) -> int:public int longestSharedLead(int[] northern, int[] southern)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.