Leaderboard
Showing:
C++ 2-D Arrays | Set-1
School Accuracy: 29.41% Submissions: 17 Points: 0

Given an 2-d array of integers having N*N elements, print the transpose of the array. 

Example 1:

​Input : arr[] = {{1,2,3}, {4,5,6}, {7,8,9}} 
        and N = 3
Output : 1 4 7 2 5 8 3 6 9
Explanation:
1 2 3       1 4 7
4 5 6 ----> 2 5 8
7 8 9       3 6 9
Transpose of array.


​Example 2:

Input : arr[ ] = {{1, 2}, {1, 2}} and N = 2 
Output :  1 1 2 2

 

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function transpose() that takes a two-dimension array (arr), sizeOfArray (n), and return the transpose of the array. The driver code takes care of the printing.

Expected Time Complexity: O(N2).
Expected Auxiliary Space: O(1).

 

Constraints:
1 ≤ N ≤ 100
0 ≤ A[i] ≤ 1000

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.

C++ 2-D Arrays | Set-1

Output Window