Problem · String
Max Distance
Learn this problemProblem statement
The distance between 2 binary strings is the sum of their lengths after removing the common prefix.
Given a list of binary strings, pick a pair that gives you maximum distance among all possible pairs and return that distance.
Function
maxDistance(binaryStrings: List<String>) → intExamples
Example 1
binaryStrings = ["1011000", "1011110"]return = 6The common prefix for these two numbers is 1011, so the distance is len("000") + len("110") = 3 + 3 = 6.
Constraints
2 ≤ binaryStrings.size() ≤ 10^5- Each string is non-empty and contains only
0and1. - The total length of all strings is at most
2 * 10^5. - Two different list positions form a pair; their string values may be equal.