
Asked in Arcesium
Spiral Order Traversal of a Binary Tree
Given a binary tree with N
nodes, your task is to output the Spiral Order traversal of the binary tree.
Input:
The input consists of a single line containing elements of the binary tree provided in level order. The node values are separated by a space, and -1
represents a null node.
Output:
A line of N
space-separated integers representing the spiral order traversal of the binary tree.
Example:
Input: 1 2 3 -1 -1 4 5
Output: 1 3 2 4 5
Explanation:
The binary tree corresponding to the input is:
1
/ \
2 3
/ \
4 5
The Spiral Order traversal is: 1 3 2 4 5
Constraints:
0 <= N <= 10^4
- Where
N
is the total number of nodes in the binary tree. - Time Limit: 1 second
Note:
You are only required to implement the function that returns the spiral order traversal as a list. All input/output handling has been taken care of.

AnswerBot
4mo
Implement a function to output the Spiral Order traversal of a binary tree given in level order.
Traverse the binary tree in a spiral order, alternating between left to right and right to left at each ...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Arcesium
Q. 1) Maximum meetings in one room 2)Bottom view of tree 3) Serialize deserialize b...read more
Q. Number of Islands Problem Statement You are given a non-empty grid that consists...read more
Q. N-th Node From The End Problem Statement You are provided with a Singly Linked L...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Arcesium Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

