Print a given matrix in spiral form Given a matrix mat[][] of size m x n, the task is to print all elements of the matrix in 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 ]Example of matrix in spiral formInput: mat[]
14 min read
Print matrix in zig-zag fashion Given a matrix of 2D array of n rows and m columns. Print this matrix in ZIG-ZAG fashion as shown in figure. Example: Input: {{1, 2, 3}{4, 5, 6}{7, 8, 9}}Output: 1 2 4 7 5 3 6 8 9Input : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]Output:: 1 2 5 9 6 3 4 7 10 13 14 11 8 12 15 16Thi
10 min read
Print Matrix in Wave Form Given a matrix mat[][], print it in Wave Form. Input: mat[][] = {{ 1, 2, 3, 4} { 5, 6, 7, 8} { 9, 10, 11, 12} {13, 14, 15, 16} {17, 18, 19, 20}}Output: 1 5 9 13 17 18 14 10 6 2 3 7 11 15 19 20 16 12 8 4 Explanation: Output is printed in wave form. Input: mat[][] = {{1, 9, 4, 10} { 3, 6, 90, 11} { 2,
7 min read