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.
Given 'grayNumber' : 2.
As depicted from above image, the gray code sequence is 0,1,3,2.
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’.
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’.
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
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’)