Question bank › Trees
Dsa Trees Medium

Level Order Traversal with Depths

Given a binary tree, output its level order traversal as a list of lists, where each inner list corresponds to the values of nodes at that level of the tree. Additionally, include the depth of each level starting from 0. Input format: - The first line contains an integer N (1 ≤ N ≤ 1000), the number of nodes. - The next N lines contain node values and their left and right children (use -1 for non-existent children). Output format: - Print level order traversal as a list of lists, along with the corresponding depth for each level. Example input: 3 1 2 3 2 -1 -1 3 -1 -1 Example output: [[1], [2, 3]]

Key concepts

binary treelevel orderdepth

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.