Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-344

Longest Common Prefix Length

Problem

The longest common prefix length is the number of leading characters shared by two strings.

Given the two strings, return the length.

Hint

Stop at the first mismatch.

Test cases

case 1
in: ["prefix","prelude"]
expected: 3
case 2
in: ["abc","xyz"]
expected: 0
case 3
in: ["same","same"]
expected: 4
Starter codePython
def longest_common_prefix_length(a, b):
    # Your code here
    pass

3 test cases · run your code against them in the editor