Challenge: Print level-order Traversal

Let’s print the level-order traversal of a tree.

Problem

Given a binary tree, perform a level-order traversal by completing the PrintBreadthFirst() function. A level-order traversal is a traversal in which a tree is explored level-by-level. The nodes present at the same level are explored together.

Input

A binary tree.

Output

Let’s look at the illustration below to better understand the problem.

Sample input

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.