11package com .thealgorithms .matrix ;
22
33// Problem Statement
4+
5+ import com .thealgorithms .matrix .utils .MatrixUtil ;
6+
47/*
58We have given an array of m x n (where m is the number of rows and n is the number of columns).
69Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.
@@ -17,41 +20,17 @@ public final class MirrorOfMatrix {
1720 private MirrorOfMatrix () {
1821 }
1922
20- public static int [][] mirrorMatrix (final int [][] originalMatrix ) {
21- if (originalMatrix == null ) {
22- // Handle invalid input
23- return null ;
24- }
25- if (originalMatrix .length == 0 ) {
26- return new int [0 ][0 ];
27- }
28-
29- checkInput (originalMatrix );
23+ public static double [][] mirrorMatrix (final double [][] originalMatrix ) {
24+ MatrixUtil .validateInputMatrix (originalMatrix );
3025
3126 int numRows = originalMatrix .length ;
3227 int numCols = originalMatrix [0 ].length ;
3328
34- int [][] mirroredMatrix = new int [numRows ][numCols ];
29+ double [][] mirroredMatrix = new double [numRows ][numCols ];
3530
3631 for (int i = 0 ; i < numRows ; i ++) {
37- mirroredMatrix [i ] = reverseRow (originalMatrix [i ]);
32+ mirroredMatrix [i ] = MatrixUtil . reverseRow (originalMatrix [i ]);
3833 }
3934 return mirroredMatrix ;
4035 }
41- private static int [] reverseRow (final int [] inRow ) {
42- int [] res = new int [inRow .length ];
43- for (int i = 0 ; i < inRow .length ; ++i ) {
44- res [i ] = inRow [inRow .length - 1 - i ];
45- }
46- return res ;
47- }
48-
49- private static void checkInput (final int [][] matrix ) {
50- // Check if all rows have the same number of columns
51- for (int i = 1 ; i < matrix .length ; i ++) {
52- if (matrix [i ].length != matrix [0 ].length ) {
53- throw new IllegalArgumentException ("The input is not a matrix." );
54- }
55- }
56- }
5736}
0 commit comments