# Exchange matrix columns

Tue Feb 08 2022 08:41:01 GMT+0000 (UTC)

```class Solution
{
//Function to exchange first column of a matrix with its last column.
static void exchangeColumns(int matrix[][])
{
int temp = 0;
for (int i=0; i<matrix.length; i++)
{
temp = matrix[i][0];
matrix[i][0] = matrix[i][matrix[i].length-1];
matrix[i][matrix[i].length-1] = temp;
}
}
}```
content_copyCOPY

Exchange matrix columns You are given a matrix of dimensions (n1 x m1). You have to exchange its first column with the last column. Example 1: Input: n1 = 4, m1 = 4 matrix[][] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15,16}} Output: 4 2 3 1 8 6 7 5 12 10 11 9 16 14 15 13 Explanation: Matrix is as follow: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 After exchanging first column with last column, we have matrix as follows: 4 2 3 1 8 6 7 5 12 10 11 9 16 14 15 13 Example 2: Input: n1 = 2, m1 = 3 matrix[][] = {{4, 3, 2}, {1, 5, 6}} Output: 2 3 4 6 5 1 Explanation: Matrix is as follows: 4 3 2 1 5 6 After exchanging columns matrix will be: 2 3 4 6 5 1 Your Task: You don't need to take input or print anything. Complete the function exchangeColumns() that takes the matrix as input parameter and modifies it in place by exchanging its first column with its last column. Expected Time Complexity: O(n1 * m1) Expected Auxiliary Space: O(1) Constraints: 1 <= n1, m1<= 100 0 <= arr[i] <= 100

https://practice.geeksforgeeks.org/problems/exchange-matrix-columns-1587115620/1/?track=DSASP-Matrix&batchId=190
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}