Loading content...
A reflected binary sequence of order n is a specific arrangement of 2ⁿ distinct integers with unique mathematical properties. This sequence has the following characteristics:
[0, 2ⁿ - 1].0.This sequence is particularly useful in digital communications and error minimization applications because consecutive values change minimally, reducing the chance of errors during transitions.
Given a positive integer n representing the order of the sequence, generate and return any valid reflected binary sequence of that order. Multiple correct sequences may exist for a given n, and any one of them is acceptable as output.
n = 2[0,1,3,2]The binary representations of [0,1,3,2] are [00,01,11,10].
Alternative valid sequences include [0,2,3,1] with binary [00,10,11,01], which also satisfies all constraints.
n = 1[0,1]With n=1, we have 2¹ = 2 elements in the range [0,1]. The sequence [0,1] represents binary [0,1], where 0 and 1 differ by exactly one bit.
n = 3[0,1,3,2,6,7,5,4]The binary representations are [000,001,011,010,110,111,101,100]. Each consecutive pair differs by exactly one bit, and the first (000) and last (100) elements also differ by one bit.
Constraints