Given a number ‘grayNumber’. Find the gray code sequence.
Conditions for a gray code sequence :
1. Gray code sequence contains numbers from 0 to 2^'grayNumber'-1 in bit/binary form.
2. Two consecutive gray code sequence numbers only differ by 1 bit.
3. Gray code sequence must start with 0.
Example :
Given 'grayNumber' : 2.

As depicted from above image, the gray code sequence is 0,1,3,2.
Note :
1. The output sequence must contain the decimal representation of numbers instead of the binary form.
2. There can be multiple answers print anyone.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of every test case contains an integer ‘grayNumber’.
Output Format :
For each test case, return the ‘list/vector’ of the Gray code sequence.
The output is ‘Valid’ if returned gray code sequence is correct. Else ‘Invalid’.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 2
0 <= grayNumber <= 15
Time Limit : 1 sec
2
2
3
Valid
Valid
For first test case,
Given 'grayNumber' : 2
Bits representation of a number from 0 to 2^2-1 = 3 is “ 00, 01, 10, 11’’.
But we have arranged these bits in such a way that two consecutive bits only differ by 1.
Only one possible way is “00, 01, 11, 10 ”.
Hence return value of every number “ 00 - 0 , 01 - 1, 11 - 3, 10 - 2”.
Sequence : {0, 1, 3, 2}.
For second test case,
Given 'grayNumber' : 3
Bits representation of a number from 0 to 2^3-1 =7 is “000, 001, 010, 011, 100, 101, 110, 111’’.
But we have arranged these bits in such a way that two consecutive bits only differ by 1.
One of the possible ways is “000, 001, 011, 111, 101, 100, 110, 010”.
Hence return value of every number “000 - 0, 001 - 1, 011 - 3, 111 - 7, 101 - 5, 100 - 4, 110 - 6, 010 - 2 ”.
Sequence : {0, 1, 3, 7, 5, 4, 6, 2}.
One another possible sequence can be : {0, 1, 3, 2, 6, 7, 5, 4}.
2
4
1
Valid
Valid
For first test case,
Given 'grayNumber' : 4
Sequence : {0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8}.
For second test case,
Given 'grayNumber' : 1
Sequence : {0, 1}.
Observe the pattern of the Gray code sequence.
Suppose are finding an answer for ‘N’ size but we have already the solution for ‘N-1’. then use the previous answer for a new answer. (where ‘N’ is ‘grayNumber’)
O(2^N*Log(N)), where ‘N’ is the given number ‘grayNumber’.
We are iterating the loop of size ‘2^N and Log(n) represents the number of bits in number ‘N’ in binary bits representation. Therefore, the overall time complexity will be O(2^N*Log(N)).
O(2^N), where 'N' is the given number 'grayNumber'.
We are using a list/vector ('grayCode') of size 2^'N' to store the numbers. Therefore, the overall space complexity will be O(2^N).