#### The starting point of each scan: i % 2 == 0 (up-right): if i < m, there are more rows down below (like 9 in the example), start from the first element in row ( **matrix** [i] [0]) otherwise we've reached the end of m rows (like 11 in the example), so start from the last row but i - m + 1 position ( **matrix** [m - 1] [i - m + 1]) After we find the. Complete the function spirallyTraverse that takes **matrix**, r and c as input parameters and returns a list of integers denoting the spiral **traversal** of **matrix**. Expected Time Complexity: O (r*c) Expected Auxiliary Space: O (r*c), for returning the answer only. Constraints: 1 <= r, c <= 100. 0 <= matrixi <= 100. gfci keep going bad. The **zigzag** **traversal** is: 18 20 30 65 45 34 60 12 50 98 82 31 59 71 41. Approach 1: Using Two Stacks. The **zigzag** **traversal** of a binary tree can be achieved using two stacks. Treat the first stack as the currentLevel stack and the second stack as the nextLevel stack. A variable is also required to get the information about the current level order.

**ZigZag traversal**of Binary Tree by having 2 stacks (Stack - A LIFO data structure) for alternate (left to right) and (right to the left)

**traversal**and then print the nodes alongside. So, Step1: We create 2 stacks of type TreeNode. Initially stack1 stores root and stack2 is empty. Constraints: 1 <= r, c <= 100.. Approach - Using Two Stacks. We could achieve

**ZigZag traversal**of Binary Tree by having 2 stacks (Stack - A LIFO data structure) for alternate (left to right) and (right to the left)

**traversal**and then print the nodes alongside. So, Step1: We create 2. When we think about a

**zigzag**

**traversal**, it starts on level 1 i.e. root node from left to right and then on level 2 from right to left and the again from left to right on level 3. So there is a alternating state that's being introduced. Alternating state can be depicted using a boolean and that's what we are doing here.