Given an integer N, the duty is to generate an array A[] of size N such that it satisfies the next situations for all 1 ≤ i ≤ N−1:
 A_{i} is a number of of A_{i1} when i is odd
 A_{i }will not be a number of of A_{i1} when i is even
 All A_{i} are pairwise distinct
 1 ≤ A_{i} ≤ 2⋅N
Word: If there are a number of solutions print any of them.
Examples:
Enter: N = 4
Output: 3 6 4 8
Rationalization: [3, 6, 4, 8] is a sound array as a result of:
A1 = 3 is a number of of A2 = 6
A2 = 6 will not be a number of of A3 = 4
A3 = 4 is a number of of A4 = 8.Enter: N = 6
Output: 4 8 5 10 6 12
Strategy: The issue may be solved primarily based on the next remark:
Observations:
Let x = N − ⌈N / 2⌉ + 1. Then, the next sequence is legitimate: [x, 2⋅x, x + 1, 2⋅(x + 1), x + 2, …]
 It’s simple to see that the weather at odd indices are in growing order from x→N. Equally, the weather at even indices are in growing order from 2⋅x→2⋅N (from 2⋅x→2⋅(N − 1) when N is odd).
 Then, 2⋅x = 2⋅(N − ⌈N / 2⌉ + 1) > N implies the units {x, x + 1, …, N} and {2⋅x, 2⋅(x + 1), …, 2⋅N} are disjoint. Subsequently, all parts of the above sequence are distinctive.
 A_{i} is a number of of A_{i1} may be trivially verified to be true for all odd
A_{i} will not be a number of of A_{i1} holds true for all even i.Thus, the supplied sequence fulfills all necessities of the issue, and is subsequently legitimate!
Observe the beneath steps to resolve the issue:
 Initialize a variable oddElement = (N / 2) + 1 for odd listed parts.
 Initialize a variable evenElement = oddElement * 2 for even listed parts.
 Traverse a loop from 1 until N on i:
 If i is odd print oddElement.
 Assign evenElement = oddElement * 2.
 Increment the evenElement.
 Else print the evenElement.
 If i is odd print oddElement.
Under is the implementation of the above method.
Java

Time Complexity: O(N)
Auxiliary House: O(1)