Leaf Flip Results
Asked at Google
Reported by the problem's creator, not verified
A boolean expression is stored as a tree written with nested lists. A leaf is a boolean (true or false). An inner node is a list that starts with an operator name: ["AND", left, right], ["OR", left, right], ["XOR", left, right] for two children, or ["NOT", child] for one child. XOR is true when exactly one child is true.
Examples
Example 1
Input:
{"tree":["XOR",["OR",false,true],["AND",true,["NOT",true]]]}Output:
[true,false,true,false]Explanation: The root is
true. Flipping the first leaf (false) leaves theORattrue, so the root staystrue. Flipping the second leaf (true) makes theORfalseand the rootfalse. Flipping the third leaf (true, left child of theAND) leaves theANDfalsebecause theNOTbeside it isfalse, so the root staystrue. Flipping the last leaf (the one underNOT) makes theNOTtrue, theANDtrueand the rootfalse.