Boundary Elements of Matrix
Easy Accuracy: 66.67% Submissions: 895 Points: 2

Given an nxn matrix .In the given matrix, you have to find the boundary elements of the matrix.

Example 1:

Input: {{1, 2, 3}, {4, 5, 6}, 
{7, 8, 9}}
Output: 1 2 3 4 6 7 8 9

Example 2:

Input: {{1, 2}, {3, 4}}
Output: 1 2 3 4


Your Task:
You don't need to read or print anything. Your task is to complete the function BoundaryElements() which takes matrix as input parameter and returns a list containing the boundary elements of the matrix in the same order in which they appear in the input matrix.


Expected Time Complexity: O(n2)
Expected Space Complexity: O(1)


1 <= n <= 100

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Boundary Elements of Matrix

Output Window