Back to problems

Expression Tree Single-Leaf Mutation

Algorithm · Google · Hard

Requirements You receive a binary expression tree whose internal nodes contain AND, OR, XOR, or the unary operator NOT. Every leaf stores a boolean. First, evaluate the expression from the leaves upward and determine the value at the root. Visit the leaves in left-to-right order. At each leaf, invert only that leaf's value, obtain the resulting root value, and then return the leaf to its original state before continuing. Produce a list containing the root value generated by…

Checking your access…