FastPrepValidating Magical Binary Strings with RegEx (NG)

Validating Magical Binary Strings with RegEx (NG)

Wayfair logoWayfair● EasyFULLTIMEOA
Learn

Problem statement

We consider a binary string (i.e., a string consisting of 0s and 1s) to be magical if it satisfies the following constraints:

  • It starts with the character 1.
  • The string contains at least two 0s.
  • The string contains an even number of 0s.

For example, 1010001 is magical, but 01000 and 1000 are not.

Complete the code in the editor below by replacing the blank (i.e., “________”) with a regular expression that matches magical strings according to the criteria above. Locked code in the editor prints True for each correct match and False for each incorrect match.

Function

isMagicalString(s: String) → String

Replace the blank in the editor below with a regex expression. If your expression matches, the code will print True. Otherwise it will print False.

Examples

Example 1

s = "1001"return = "True"

1001 starts with a 1 and contains an even number of 0s, so it's magical.

Example 2

s = "11000"return = "False"

11000 starts with a 1 but contains an odd number of 0s, so it's not magical.

Example 3

s = "0101"return = "False"

0101 starts with a 0, so it's not magical.

Example 4

s = "1010"return = "True"

1010 starts with a 1 and contains an even number of 0s, so it's magical.

Example 5

s = "1111"return = "False"

1111 starts with a 1 but doesn't contain at least two 0s, so it's not magical.

Constraints

  • 1 ≤ query ≤ 10^3
  • 1 ≤ string length ≤ 10^3

More Wayfair problems

See Wayfair hiring insights
public String isMagicalString(String s) {
  // write your code here
}
s"1001"
expected"True"
Checking account…