Breadth-First Values of a Binary Tree
Updated
Problem statement
Given the root of a binary tree, return its node values in breadth-first order.
Visit nodes level by level from top to bottom, and from left to right within each level. Return an empty array for an empty tree.
Function
breadthFirstValues(root: TreeNode) → int[]Examples
Example 1
root = [3,9,20,null,null,15,7]return = [3,9,20,15,7]The traversal visits the root, then 9 and 20, then 15 and 7.
Example 2
root = [1,2,3,4,5]return = [1,2,3,4,5]Values on the same level are emitted from left to right.
Example 3
root = []return = []An empty tree has no values to visit.
Constraints
- The tree contains at most
100000nodes. - Each node value fits in a signed 32-bit integer.
More Figma Onsite Interview questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Sort Documents Left to RightONSITE INTERVIEW · Seen Aug 2026
- Symmetric Binary TreeONSITE INTERVIEW · Seen Feb 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Nested Template Variable ExpansionONSITE INTERVIEW · Seen Jun 2024
- Parse, Validate, and Repair Markdown FormattingONSITE INTERVIEW · Seen Jun 2024
Similar questions at other companies
- Binary Tree Level-Order Traversal by LevelsAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
- Zigzag Level-Order TraversalFlipkart · ONSITE INTERVIEW
- Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Binary Tree Zigzag Level Order TraversalMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Top View of a Binary TreeCapillary Technologies · ONSITE INTERVIEWCapillary Technologies interview questions
- Independent Level Iterators Over a Shared Binary TreeGoogle · PHONE SCREENGoogle interview questions
- Check Whether All Leaves Are at the Same LevelAmazon · ONSITE INTERVIEW
- Tree Level with the Most NodesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Mirror Image Binary TreesExpedia · ONSITE INTERVIEWExpedia interview questions
- Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions