Given a matrix of size Row x Col Print the boundary elements of the matrix. Boundary elements are those elements which are not surrounded by elements on all four directions, i.e. elements in the first row, first column, last row and last column.
Input : 1 2 3 4 5 6 7 8 9 Output: 1 2 3 4 6 7 8 9
- Take the matrix as input from the user of N × M dimension.
- Print the border elements of the matrix using for loop.
Below is the implementation of the problem statement:
Input Matrix is : 123 456 789 Resultant Matrix is : 123 4 6 789
Time Complexity: O(N × M), where n and m are the dimensions of the matrix.
Space Complexity: O(N × M).
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.