ZigZag Tree Traversal
Difficulty: Medium Accuracy: 54.05% Submissions: 182K+ Points: 4 Average Time: 30m
Given the root of a binary tree. You have to find the zig-zag level order traversal of the binary tree.
Note: In zig zag traversal we traverse the nodes from left to right for odd-numbered levels, and from right to left for even-numbered levels.
Examples:
Input: root = [1, 2, 3, 4, 5, 6, 7]
Output: [1, 3, 2, 4, 5, 6, 7]
Explanation:
Level 1 (left to right): [1]
Level 2 (right to left): [3, 2]
Level 3 (left to right): [4, 5, 6, 7]
Final result: [1, 3, 2, 4, 5, 6, 7]
Input: root = [7, 9, 7, 8, 8, 6, N, 10, 9]
Output: [7, 7, 9, 8, 8, 6, 9, 10]
Explanation:
Level 1 (left to right): [7]
Level 2 (right to left): [7, 9]
Level 3 (left to right): [8, 8, 6]
Level 4 (right to left): [9, 10]
Final result: [7, 7, 9, 8, 8, 6, 9, 10]
Expected Complexities
Time Complexity: O(n)
Auxiliary Space: O(n)
#coding #GeeksforGeeks #ProblemOfTheDay #JavaScript
---
introduction:
name: "Jagadeesh Kumar S"
contact: "+91 73972 85837 | [email protected]"
description: "A problem-solving enthusiast passionate about coding challenges."
technical_achievements:
"Solved 100+ daily coding challenges on GeeksforGeeks"
"Ranked in the top 130 on SRM Institute of Science and Technology's GeeksforGeeks leaderboard"
"Maintained a 100+ day streak for Problem of the Day"
github:
contributions: "Solutions available at https://github.com/JKS-sys/Solution-T..."
---
Информация по комментариям в разработке