java.lang.Object
g1201_1300.s1238_circular_permutation_in_binary_representation.Solution

public class Solution extends Object
1238 - Circular Permutation in Binary Representation.<p>Medium</p> <p>Given 2 integers <code>n</code> and <code>start</code>. Your task is return <strong>any</strong> permutation <code>p</code> of <code>(0,1,2.....,2^n -1)</code> such that :</p> <ul> <li><code>p[0] = start</code></li> <li><code>p[i]</code> and <code>p[i+1]</code> differ by only one bit in their binary representation.</li> <li><code>p[0]</code> and <code>p[2^n -1]</code> must also differ by only one bit in their binary representation.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 2, start = 3</p> <p><strong>Output:</strong> [3,2,0,1]</p> <p><strong>Explanation:</strong> The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 3, start = 2</p> <p><strong>Output:</strong> [2,6,7,5,4,0,1,3]</p> <p><strong>Explanation:</strong> The binary representation of the permutation is (010,110,111,101,100,000,001,011).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 16</code></li> <li><code>0 <= start < 2 ^ n</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • circularPermutation

      public List<Integer> circularPermutation(int n, int start)