Question bank › Trees
Dsa Trees Easy

Inverted Tree Levels

Write a function that reads a binary tree and outputs its level order traversal, but with each level's node values inverted. The first level (root) stays unchanged. Input format: - The first line contains an integer N, the number of nodes in the tree. - The following N lines contain integers representing each node's value in level-order traversal. - Use -1 to indicate 'null' nodes. Output format: - Print the inverted level order traversal as space-separated values for each level, maintaining the original order of levels. Example: Input: 5 1 2 3 -1 -1 4 5 Output: 1 3 2 5 4

Key concepts

treeslevel orderinversion

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.