Problem · String

Max Distance

Learn this problem
MediumGoogleOA
See Google hiring insights

Problem 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>) → int

Examples

Example 1

binaryStrings = ["1011000", "1011110"]return = 6
The 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 0 and 1.
  • 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

drafts saved locally
public int maxDistance(List<String> binaryStrings) {
    // write your code here
}
binaryStrings["1011000", "1011110"]
expected6
checking account