Zig Zag Level order traversal of a tree using single array Write a function to print spiral order traversal of a tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7. We have discussed naive approach and two stack based approach in Level Order with recursion and multiple stacksThe idea behind this approach is first we have to take a queue, a dire
9 min read
Clockwise Spiral Traversal of Binary Tree Given a Binary Tree. The task is to print the circular clockwise spiral order traversal of the given binary tree. For the above binary tree, the circular clockwise spiral order traversal will be 1, 4, 5, 6, 7, 2, 3. Examples: Input : 10 / \ 12 13 / \ 14 15 / \ / \ 21 22 23 24 Output : 10, 24, 23, 22
15+ min read
Print a given matrix in spiral form using direction tracking method Given a 2-D matrix mat[][], the task is to print it in the spiral form.Examples: Input: mat[][] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}} Output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 Input: mat[][] = { {1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}} Ou
14 min read
Count unique stairs that can be reached by moving given number of steps forward or backward Given an integer N, representing the number of stairs, valued from 1 to N, and a starting position S, the task is to count the maximum number of unique stairs that can be reached by moving exactly A or B stairs steps forward or backward from any position, any number of times. Examples: Input: N = 10
8 min read