Minimum Policy Flips in a Binary Expression Tree

A policy engine stores a Boolean expression in a binary tree. A leaf is a literal: 0 means false and 1 means true. An internal node is an operator: 2 means OR, 3 means AND, 4 means XOR, and 5 means NOT. NOT uses its left child and has no right child.

The tree is encoded in level order, with null for a missing child. You may flip any leaf literal at a cost of one. A flip changes 0 to 1 or 1 to 0; operators cannot be changed. Return the minimum total cost needed for the root expression to equal target.

Examples
Input: [[2,0,1],true]
Output: 0
Hints

Minimum Policy Flips in a Binary Expression Tree

A policy engine stores a Boolean expression in a binary tree. A leaf is a literal: `0` means false and `1` means true. An internal node is an operator: `2` means OR, `3` means AND, `4` means XOR, and `5` means NOT. NOT uses its left child and has no right child.