Longest Zigzag Path In A Binary Tree
1. You are given a partially written function to solve.Input Format
2. Given a binary tree root, a ZigZag path for a binary tree is defined as follow:
a. Choose any node in the binary tree and a direction (right or left).
b. If the current direction is right then move to the right child of the current node otherwise move to the left child.
c. Change the direction from right to left or right to left.
d. Repeat the second and third step until you can't move in the tree.
3.Zigzag length is defined in terms of edges. (A single node has a length of 0).
4. Return the longest ZigZag path contained in that tree.
Input is managed for you.Output Format
Output is managed for you.Question Video
0 <= Number of Nodes <= 10^9Sample Input
-10^9 <= value of Node data <= 10^9
15Sample Output
1
1
-1
1
1
-1
1
-1
-1
1
-1
-1
1
-1
-1
4
-
Asked in Companies
-
Related Topics
Video Solution
Code Solution
{ }
{ }
Run