Skip to content
LC-1238 Medium LeetCode

1238. Circular Permutation in Binary Representation

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 72% Topics: Math, Backtracking, Bit Manipulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(2^n)
# Space: O(1)

class Solution(object):
    def circularPermutation(self, n, start):
        """
        :type n: int
        :type start: int
        :rtype: List[int]
        """
        return [start ^ (i>>1) ^ i for i in xrange(1<<n)]

Solution from kamyu104/LeetCode-Solutions · MIT