EXERCISE · AlgoCasts

Level width

Given the root node of a tree, return an array where each element is the width of the tree at each level.

3 testsAlgoCastsGPL-3.0exercise 23 of 26

Directions

Directions

Given the root node of a tree, return an array where each element is the width of the tree at each level.

Examples#

JS
Given:  0/ |  \1   2   3|       |4       5Answer: [1, 3, 2]

Try it first#

Copy the stub, make the 3 tests pass on your machine, then open the solution. The reveal is remembered per page in this browser.

JSexercises/levelwidth/index.js
function levelWidth(root) {} module.exports = levelWidth;

See also