FastPrepFastPrep
Problem Brief

Validating Magical Binary Strings with RegEx (NG)

FULLTIMEOA

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 Description

    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.

    1Example 1

    Input
    s = "1001"
    Output
    "True"
    Explanation

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

    2Example 2

    Input
    s = "11000"
    Output
    "False"
    Explanation

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

    3Example 3

    Input
    s = "0101"
    Output
    "False"
    Explanation

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

    4Example 4

    Input
    s = "1010"
    Output
    "True"
    Explanation

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

    5Example 5

    Input
    s = "1111"
    Output
    "False"
    Explanation

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

    Constraints

    Limits and guarantees your solution can rely on.

    • 1 ≤ query ≤ 10^3
    • 1 ≤ string length ≤ 10^3
    public String isMagicalString(String s) {
      // write your code here
    }
    
    Input

    s

    "1001"

    Output

    "True"

    Sign in to submit your solution.