Tree Node Levels and Balance

Asked at NetflixOnsite

Reported by the problem's creator, not verified

A binary tree node is a list [value, left, right], where left and right are nodes or None. You are given the root node of a binary tree.

Examples

  1. Example 1

    Input: {"root":[1,[2,[4,null,null],[5,null,null]],[3,null,null]]}

    Output: [[1,0,true],[2,1,true],[4,2,true],[5,2,true],[3,1,true]]

    Explanation: Records follow preorder: 1, 2, 4, 5, 3, with levels 0, 1, 2, 2, 1. Every node's left and right subtree heights differ by at most 1, so each record ends in True.

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.