Print all the boundary nodes of Binary Tree


Asked In: LinkedinGoldman Sachs

rint all the boundary nodes in the binary tree.Boundary includes left boundary, leaves, and right boundary in anti clockwise direction in O(n) Time Complexity

Example:

Binary Tree given as an input.O(n) : One complete traversal for leaves and two traversals upto depth of binary tree for left and right boundary

Output: [1 2 7 17 9  8 4 3]

Problem level: Medium