Print 2D Matrix

You are given a 2D integer matrix with N rows and M columns. Your task is to print all the elements of the matrix in the same order as they appear.

Print each row on a separate line, with elements separated by a single space.

Example 1:

Input:

Matrix = [
    [1, 2, 3],
    [4, 5, 6]
]

Output:

1 2 3
4 5 6

Example 2:

Input:

Matrix = [
    [-10, 10],
    [2, 3]
]

Output:

-10 10
2 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N, M <= 100
  • -105 <= matrix[i][j] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
void printMatrix(int** arr, int N, int M) {
// Write your logic here
}
};
Test Case

Input:

Matrix