Longest Common Prefix Length
Problem statement
You are given two strings a and b.
Return the length of their longest common prefix: the longest string that begins at index 0 in both inputs. Character comparisons are case-sensitive.
Function
longestCommonPrefixLength(a: String, b: String) → intExamples
Example 1
a = "flower"b = "flow"return = 4Both strings begin with flow, and the second string ends after four characters.
Example 2
a = "abc"b = "xyz"return = 0The first characters differ, so the common prefix is empty.
Constraints
0 <= a.length, b.length <= 105- The combined input length is at most
2 * 105. - Both strings contain printable ASCII characters.