[Python] Find anagram, explained
This is in fact question about anagrams: given string we need to find if we have another string from list of powers of too, which is anagram of original string.
This is in fact question about anagrams: given string we need to find if we have another string from list of powers of too, which is anagram of original string. Let us iterate through all powers of two and check if count of this number is equal to count of given number `N`. \n\n**Complexity**: time complexity will be `O(log^2 N)`: we check `O(log N)` numbers, each of them have `O(log N)` digits at most. In fact it can be improved to `O(log^2N)`, because there can be at most `4` numbers with given number of digits, but here it just not worth it. Space complexity is `O(log N)`.\n\n```\nclass Solution:\n    def reorderedPowerOf2(self, N):\n        cnt = Counter(str(N))\n        return any(cnt == Counter(str(1<<i)) for i in range(30))\n```\n\nIf you have any question, feel free to ask. If you like the explanations, please **Upvote!**
[]