- bfs is more suited as it traverses breath first
- solution is dfs lol
- just have to track each level while traversing left and right child
- push node value in the same array index
- i.e. root node, 0, goes into arr[0]
- first left and right child nodes, count 1, goes into arr[1] etc..
Solution
// https://leetcode.com/problems/binary-tree-level-order-traversal/varlevelOrder=function (root) {let output = [];if (!root) {return []; }functionwalk(node, count) {// base conditionif (!node) {return; }// preif (!output[count]) {output.push([]); }// push into output array of the same level output[count].push(node.val);// recursewalk(node.left, count +1);walk(node.right, count +1);// post }walk(root,0);return output;};