public static void Main()
int[, ] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
public static void PrintSnakeMatrix(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
Console.Write($"{arr[i, j]} ");
for (int j = cols - 1; j >= 0; j--)
Console.Write($"{arr[i, j]} ");
public static void PrintSpiralMatrix(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
int top = 0, left = 0, right = cols - 1, bottom = rows - 1;
while (top <= bottom && left <= right)
for (int i = left; i <= right; i++)
Console.Write($"{arr[top, i]} ");
for (int i = top; i <= bottom; i++)
Console.Write($"{arr[i, right]} ");
for (int i = right; i >= left; i--)
Console.Write($"{arr[bottom, i]} ");
for (int i = bottom; i >= top; i--)
Console.Write($"{arr[i, left]} ");
public static void BoundryTraversal(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
for (int i = 0; i < cols; i++)
Console.Write($"{arr[0, i]} ");
for (int i = 0; i < rows; i++)
Console.Write($"{arr[i, 0]} ");
for (int i = 0; i < cols; i++)
Console.Write($"{arr[0, i]} ");
for (int i = 1; i < rows; i++)
Console.Write($"{arr[i, cols - 1]} ");
for (int i = cols - 2; i >= 0; i--)
Console.Write($"{arr[rows - 1, i]} ");
for (int i = rows - 2; i > 0; i--)
Console.Write($"{arr[i, 0]} ");
public static void Print2DMatrix(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
Console.Write($"{arr[i, j]} ");
public static void Swap(int[, ] arr, int i, int j)
public static void TransposeMatrixNaive(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
int[, ] temp = new int[rows, cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
public static void TransposeMatrix(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
for (int i = 0; i < rows; i++)
for (int j = i + 1; j < cols; j++)
public static void Rotate90Deg(int[, ] arr)
public static void ReverseColumns(int[, ] arr)
int rows = arr.GetLength(0);
int cols = arr.GetLength(1);
for (int i = 0; i < rows; i++)
int low = 0, high = rows - 1;
arr[low, i] = arr[high, i];