/* Approach:- get the left most depth- get the right most depth- if left most depth is greater than then -- then keep looping and printing node data till left most node is not null- else if right most depth is greater then-- keep looping and printing node data till right most node is null-- OUTPUT -> print the tree which is deepest*/function topView(node) { const maxLenLeftChain = traverseTreeL(node); const maxLenRightChain = traverseTreeR(node); // if (maxLenLeftChain > maxLenRightChain) { // 4, 3 while (true) { if (node != null) { console.log(node.data); node = node.left } else { break; } } } else { while (true) { if (node != null) { console.log(node.data); node = node.right; } else { break; } } }}function traverseTreeL(node) { if (node.left != null) { return 1 + traverseTreeL(node.left); } return 0;}function traverseTreeR(node) { if (node.right != null) { return 1 + traverseTreeR(node.right); } return 0;}const rootNode = { data: 1};const rootTwo = { data: 2};const rootThree = { data: 3};const rootFour = { data: 4};const rootFive = { data: 5};rootNode.left = rootTwo;rootNode.right = rootThree;rootThree.right = rootFour;topView(rootNode);