Question bank › Trees
Dsa Trees Medium

Binary Tree Inversion

Write a function to invert a binary tree. This means that for every node in the tree, we swap the left and right children. Inverting a tree can be visualized as creating a mirror image of the tree. Input Format: - The first line contains an integer n (the number of nodes). - The next n lines each contain an integer value representing the node value of the binary tree in level order, with -1 indicating a null node. Output Format: - Print the level order traversal of the inverted binary tree as a space-separated string. Example: Input: 7 1 2 3 4 -1 5 6 Output: 1 3 2 6 5 4

Key concepts

treesinversiontransformation

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.