FastPrepGenerate Wildcard Binary Strings

Generate Wildcard Binary Strings

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

pattern contains 0, 1, and ?. Replace every wildcard independently with either 0 or 1 and return every resulting binary string in lexicographic order.

Function

expandWildcards(pattern: String) → String[]

Examples

Example 1

pattern = "01?0"return = ["0100","0110"]

The one wildcard produces two strings.

Example 2

pattern = "0??0"return = ["0000","0010","0100","0110"]

Two wildcards produce four strings.

Constraints

  • 0 <= pattern.length <= 20.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] expandWildcards(String pattern) {
  // Write your code here.
}
pattern"01?0"
expected["0100", "0110"]
Checking account…