Tap here to switch tabs
Problem
Submissions

Problem: Circular Permutation in Binary Representation

Try to solve the Circular Permutation in Binary Representation problem.

Statement

Given two integers n and start, return a permutation p of integers from 00 to 2n−12^n - 1 such that:

  • p[0] = start

  • p[i] and p[i + 1] differ by exactly one bit in their binary representation for all 0≤i<2n−10 \leq i < 2^n - 1.

  • The first element p[0] and the last element p[2^n - 1] also differ by exactly one bit in their binary representation.

Constraints:

  • 1≤1 \leq n ≤16\leq 16

  • 0≤0 \leq start <2n< 2^n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Circular Permutation in Binary Representation

Try to solve the Circular Permutation in Binary Representation problem.

Statement

Given two integers n and start, return a permutation p of integers from 00 to 2n−12^n - 1 such that:

  • p[0] = start

  • p[i] and p[i + 1] differ by exactly one bit in their binary representation for all 0≤i<2n−10 \leq i < 2^n - 1.

  • The first element p[0] and the last element p[2^n - 1] also differ by exactly one bit in their binary representation.

Constraints:

  • 1≤1 \leq n ≤16\leq 16

  • 0≤0 \leq start <2n< 2^n