Geeksforgeeks

Error

Given a positive integer **n** that represents dimensions of a 4n x 4n matrix with values from 1 to 4*n*4*n filled from left to right and top to bottom. Your task is to form two coils from matrix and print the coils.

Follow the given examples for better understanding.

**Example 1:**

Input:n =1Output:10 6 2 3 4 8 12 16 7 11 15 14 13 9 5 1Explanation:The matrix is 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 So, the two coils are as given in the Ouput.

**Example 2:**

Input:n =2Output:36 28 20 21 22 30 38 46 54 53 52 51 50 42 34 26 18 10 2 3 4 5 6 7 8 16 24 32 40 48 56 64 29 37 45 44 43 35 27 19 11 12 13 14 15 23 31 39 47 55 63 62 61 60 59 58 57 49 41 33 25 17 9 1Explanation:

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **formCoils()** which takes an Integer n as input and returns a vector of two vectors representing coil1 and coil2.

**Expected Time Complexity:** O(n^{2})

**Expected Auxiliary Space:** O(n^{2})

**Constraints:**

1 <= n <= 20

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login 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?

YesLoading...

Form coils in a matrix

...