Level Order Traversal BFS Problem
Level Order Traversal BFS Problem — ExecCode Medium DSA Practice
Solve the Level Order Traversal BFS problem on ExecCode. Free online medium DSA practice in Tree. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given the root of a binary tree, return the level order traversal of its nodes' values — that is, read the tree from left to right, one full level at a time. Each level of the tree becomes its own inner array in the result, ordered from the root level down to the deepest leaves.
Examples
Input root = [3, 9, 20, 8, 10, 15, 7, 4]; Output [[3], [9, 20], [8, 10, 15, 7], [4]]. Input root = [1, 2, 3]; Output [[1], [2, 3]]. Input root = [1]; Output [[1]]
Constraints
The number of nodes in the tree is in the range [0, 2000]. -1000 <= Node.val <= 1000
Practice Level Order Traversal BFS free on ExecCode. Browse DSA problems, topic map, and placement guides.