Backend Engineering
Mid-Level
programming
LeetCode #107 - Binary Tree Level Order Traversal II: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from leaves to root). For example, given binary tree [3,9,20,null,null,15,7], return [[15,7],[9,20],[3]].
Input:
[3, 9, 20, null, null, 15, 7]
Output:
[[15,7],[9,20],[3]]
Constraints:
- The number of nodes in the tree is in the range [0, 2000].
- -1000 <= Node.val <= 1000.
```
## Approach
1. Initialize a queue and start BFS from the root node.
2. For each level, store the nodes in a list and add them to the result list.
3. After processing all levels, reverse the result list.
## Complexity
**Time:** O(n)
**Space:** O(n)
where n is the number of nodes in the tree.
## Trade-offs
- Using an iterative approach with a queue avoids deep recursion and potential stack overflow.
```
Trusted by 100+ professionals preparing for interviews
Trusted by 100+ professionals
50+ Company Question Banks
5+ Supported Languages
Practice More Questions Like This
Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.
Get Started Free
More Backend Engineering Interview Prep
Describe how you would design a system to handle user authentication in a web application. What components would you include, and how would you ensure security?
Backend Engineering · Mid-Level
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.