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.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026