Evaluate Boolean Binary Tree

EasyTreesdfs

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given the root of a **full** binary tree (every node has zero or two children) that encodes a boolean expression. - A leaf holds 0 (false) or 1 (true). - An internal node holds 2, meaning **OR** of its two children, or 3, meaning **AND** of its two children. Return the boolean result of evaluating the root.

Examples

Input: root = [2,1,3,null,null,0,1]
Output: true
The AND node gives 0 AND 1 = false, and the root gives 1 OR false = true.
Input: root = [0]
Output: false
The root is the leaf false.

Constraints

  • 1 <= number of nodes <= 1000
  • Leaves hold `0` or `1`; internal nodes hold `2` or `3`
  • Every node has either 0 or 2 children

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More dfs problems