Leaf Flip Results

Asked at GoogleOnsite

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

  1. 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 the OR at true, so the root stays true. Flipping the second leaf (true) makes the OR false and the root false. Flipping the third leaf (true, left child of the AND) leaves the AND false because the NOT beside it is false, so the root stays true. Flipping the last leaf (the one under NOT) makes the NOT true, the AND true and the root false.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.