Rotate a Matrix by 180 degree Given a square matrix, the task is to turn it by 180 degrees. Note that when we rotate a matrix by 180 degree, clockwise and anticlockwise both give same results. Examples: Input: mat[][] = [[1, 2, 3] [4, 5, 6] [7, 8, 9]]Output: [9, 8, 7] [6, 5, 4] [3, 2, 1]Input: mat[][] = [[1, 2, 3, 4], [5, 6, 7,
13 min read
Javascript Program for Program to cyclically rotate an array by one Given an array, cyclically rotate the array clockwise by one. Examples: Input: arr[] = {1, 2, 3, 4, 5} Output: arr[] = {5, 1, 2, 3, 4}Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. Following are steps. 1) Store last element in a variable say x. 2) Shift all eleme
2 min read
Rotate matrix by 45 degrees Given a matrix mat[][] of size N*N, the task is to rotate the matrix by 45 degrees and print the matrix. Examples: Input: N = 6, mat[][] = {{3, 4, 5, 1, 5, 9, 5}, {6, 9, 8, 7, 2, 5, 2}, {1, 5, 9, 7, 5, 3, 2}, {4, 7, 8, 9, 3, 5, 2}, {4, 5, 2, 9, 5, 6, 2}, {4, 5, 7, 2, 9, 8, 3}}Output: 3 6 4 1 9 5 4 5
15+ min read
Javascript Program for Reversal algorithm for array rotation Write a function rotate(arr[], d, n) that rotates arr[] of size n by d elements. Example : Input : arr[] = [1, 2, 3, 4, 5, 6, 7] d = 2 Output : arr[] = [3, 4, 5, 6, 7, 1, 2] Rotation of the above array by 2 will make array Recommended: Please solve it on âPRACTICE â first, before moving on to the so
3 min read