Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Complete Leaderboard
Boundary Elements of Matrix
Easy Accuracy: 66.94% Submissions: 520 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)

 

Constraints:
1 <= n <= 100

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Boundary Elements of Matrix

Output Window