FastPrepValidating Magical Binary Strings with RegEx (NG)
Problems/Validating Magical Binary Strings with RegEx (NG)

Validating Magical Binary Strings with RegEx (NG)

Wayfair logoWayfair● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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 interview questions

  • UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
  • Container With Most WaterPHONE SCREEN · Seen Sep 2026
  • Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
  • Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
  • DFS Subsequences of a String (For MLE)OA · Seen Sep 2024
  • Number of Divisible Substrings (For MLE)OA · Seen Sep 2024
  • Smash The Bricks(NG)OA · Seen Apr 2024
  • First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
  • Time of Maximum Mall OccupancyPHONE SCREEN · Seen Apr 2022
  • Longest Common Contiguous User ActionsPHONE SCREEN · Seen Apr 2022

Similar questions at other companies

  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Count Valid Space-Delimited WordsVisa · OAVisa interview questions
  • Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
  • Validate Email AddressAccenture · OAAccenture interview questions
  • Is This Date a Weekend?Salesforce · OASalesforce interview questions
  • FIX Message ReconciliationVirtu Financial · OAVirtu Financial interview questions
  • IPv4 Address ClassificationRippling · OARippling interview questions
  • Generate Table of ContentsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Highest-Ranked University by CountryAgoda · OAAgoda interview questions
  • Counterfeit CurrencyBox · OABox interview questions
All Wayfair interview questionsSee Wayfair hiring insights
Saved
class Solution {
    public String isMagicalString(String s) {
      // write your code here
    }

}
Checking account…