Codingsimple
Binary String Expression Evaluation
Filed under Microsoft
Free read 2 of 3Parse the first digit as the initial result.
The question
Evaluate a string of 0s, 1s, and operators (AND, OR, XOR) from left to right without operator precedence.
Constraints
- Input string length <= 1000
- Only '0', '1', '&', '|', '^' characters
Examples
- Input
- 1&0|1
- Output
- 1
- Why
- (1 & 0) = 0, then (0 | 1) = 1.
Approach
Parse the first digit as the initial result.
Iterate through the string in steps of 2, capturing the operator and the next digit.
Apply the operator to the current result and the next digit, updating the result.
Tips
- What they are testing: Tests parsing logic and handling of sequential operations.
- Common mistake: Assuming standard mathematical precedence (AND before OR).
Related Microsoft questions
Collected from public candidate posts and coding forums. Updated Nov 2026.