question_slug
stringlengths 3
77
| title
stringlengths 1
183
| slug
stringlengths 12
45
| summary
stringlengths 1
160
⌀ | author
stringlengths 2
30
| certification
stringclasses 2
values | created_at
stringdate 2013-10-25 17:32:12
2025-04-12 09:38:24
| updated_at
stringdate 2013-10-25 17:32:12
2025-04-12 09:38:24
| hit_count
int64 0
10.6M
| has_video
bool 2
classes | content
stringlengths 4
576k
| upvotes
int64 0
11.5k
| downvotes
int64 0
358
| tags
stringlengths 2
193
| comments
int64 0
2.56k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reordered-power-of-2 | 🔥 Python || Easily Understood ✅ || Faster than 96% || Fast | python-easily-understood-faster-than-96-fpukz | Appreciate if you could upvote this solution\n\nSince the maximun of n is 10^9 and the len(str(10**9)) is 10 which is complicated to get all the combinations of | wingskh | NORMAL | 2022-08-26T10:16:37.006070+00:00 | 2022-08-26T10:16:37.006106+00:00 | 2,227 | false | **Appreciate if you could upvote this solution**\n\nSince the maximun of `n` is 10^9 and the `len(str(10**9))` is 10 which is complicated to get all the combinations of the digits.\n\nThus, we resolved this questions to:\n**If the digit combination of n match the digit combinations of all the power of 2**\n\nThen, it is much more easier as we need to compare n with 30 numbers only which are\n```\n2^0\n2^1\n... \n2^30\n```\n\nFor the digit combinations, there are 2 methons to handle:\n\n1) Dict: Count the occurrences of all digits\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n return sorted(str(n)) in [Counter(str(1 << i)) for i in range(30)] \n```\n\n2) String: Sort all the digits\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n return sorted(str(n)) in [sorted(str(1 << i)) for i in range(30)] \n```\n\n**Time Complexity**: \n - Counter - `O(n)`\n - Sort - `O(nlogn)`\n\n**Space Complexity**: `O(1)`\n<br />\n | 32 | 1 | ['Python'] | 3 |
reordered-power-of-2 | ✔️Python🔥One-liner✅Bit shift | Detailed explain | Beginner-friendly | Easy understand | pythonone-linerbit-shift-detailed-explai-c1lq | Main idea:\n1. We loop through 1 to 2^29 using Bit shift.\n2. And using Counter() to check if every digit in n is in power of two.\n\nOne-liner code:\npython\nc | luluboy168 | NORMAL | 2022-08-26T08:03:45.827361+00:00 | 2022-08-26T08:03:45.827402+00:00 | 1,731 | false | **Main idea:**\n1. We loop through 1 to 2^29 using Bit shift.\n2. And using Counter() to check if every digit in n is in power of two.\n\n**One-liner code:**\n```python\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n return Counter(str(n)) in [Counter(str(1 << i)) for i in range(30)]\n```\n\nAnd here\'s the code for better understand:\n```python\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n digits = Counter(str(n))\n \n for i in range(30):\n if digits == Counter(str(1 << i)):\n return True\n return False\n```\n\nFor those who don\'t know bit shift:\nThis is how power of 2 in binary looks like:\nAnd we keep left shift the number to get every power of 2.\n```\n1 -> 1\n2 -> 10\n4 -> 100\n8 -> 1000\n16 -> 10000\n32 -> 100000\n64 -> 1000000\n```\n**Please UPVOTE if you LIKE!!** | 27 | 0 | ['Python'] | 4 |
reordered-power-of-2 | Python Solution | Detailed Explanation with Example | python-solution-detailed-explanation-wit-kl9i | Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that in this question, the input n is less and equal to 10\u2079 so the powers | graceyliy29 | NORMAL | 2023-01-30T23:01:12.099324+00:00 | 2023-01-30T23:01:12.099373+00:00 | 660 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that in this question, the input n is less and equal to 10\u2079 so the powers of 2 can be 1, 2, 4, and 8 all the way up to 2 to the power of 29 since 2\xB2\u2079 is less than 10\u2079 and 10\u2079 is less than 2\xB3\u2070.\n\n\n\nSince We can reorder the digits in any order, input 218 can be reordered into 128 which is 2 to the power of 7. On the other hand, input 123 returns false since all the combinations of 123 [213, 123, 132, 231, 213, 312, 321] are not the power of 2.\n\nThe observation we can make is that reordering digits of a number in any order does not change the number of occurrences of its digits. So the main idea behind solving this question is that we want to count the occurrence of each digit in the input N and compare it with the occurrence of each digit in the powers of 2. If the occurrences are the same, it means that we can reorder the digits of N to have the resulting number as a power of 2. If the occurrence is not the same, it means we can\u2019t reorder the digits to become a power of 2.\n\n\n\nIf we consider the previous example, 218 returns true since 218 and 128 = 2\u2077 both have one 1, one 2, and one 8. 123 returns false since it does not match any powers of 2.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe start by converting the given number ```N``` to a string and then using the counter method to count the occurrences of each digit in ```N```. We use the variable ```occurrence``` to store the result. \nNext, we will use a for loop to iterate through the range of 0 to 29. In each iteration, we compare the occurrence of each digit in 2 to the power of i to the occurrences of each digit of the given number ```N```. if they are the same, we return ```True```, otherwise, we increment i and keep comparing. \nIf the loop completes and no match is found, it means the digits of ```N``` cannot be reordered to form a power of 2, we return ```False```.\n\n\n# Code\n```\nclass Solution(object):\n def reorderedPowerOf2(self, n):\n """\n :type n: int\n :rtype: bool\n """\n occurrence = Counter(str(n))\n for i in range(30):\n if (occurrence == Counter(str(2**i))):\n return True\n return False\n\n\n```\n\nCheck out the video solution for this problem:\nhttps://www.youtube.com/watch?v=4FAdMIoqRes\n | 23 | 0 | ['Python'] | 1 |
reordered-power-of-2 | Reordered Power of 2 | JS, Python, Java, C++ | Easy, Short Solution w/ Explanation | reordered-power-of-2-js-python-java-c-ea-1k20 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-03-21T08:06:15.866301+00:00 | 2021-03-21T09:04:40.633202+00:00 | 823 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the compare the result.\n\nIn that sense, the easiest solution here is to do exactly that: we can convert **N** to an array of its digits, sort it, then compare that result to the result of the same process on each power of **2**.\n\nSince the constraint upon **N** is **10e9**, we only need to check powers in the range **[0,29]**.\n\nTo make things easier to compare, we can always **join()** the resulting digit arrays into strings before comparison.\n\nThere are ways to very slightly improve the run time and memory here, but with an operation this small, it\'s honestly not very necessary.\n\n---\n\n#### ***Implementation:***\n\nPython can directly compare the lists and Java can directly compare the char arrays without needing to join them into strings. C++ can sort the strings in-place without needing to convert to an array.\n\n---\n\n#### ***Javascript Code:***\n\nThe best result for the code below is **72ms / 38.8MB** (beats 100% / 44).\n```javascript\nvar reorderedPowerOf2 = function(N) {\n let res = N.toString().split("").sort().join("")\n for (let i = 0; i < 30; i++)\n if ((1 << i).toString().split("").sort().join("") === res) return true\n return false\n};\n```\n\n---\n\n#### ***Python Code:***\n\nThe best result for the code below is **24ms / 14.1MB** (beats 98% / 76%).\n```python\nclass Solution:\n def reorderedPowerOf2(self, N: int) -> bool:\n res = sorted([int(x) for x in str(N)])\n for i in range(30):\n if sorted([int(x) for x in str(1 << i)]) == res: return True\n return False\n```\n\n---\n\n#### ***Java Code:***\n\nThe best result for the code below is **1ms / 35.8MB** (beats 97% / 88%).\n```java\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] res1 = String.valueOf(N).toCharArray();\n Arrays.sort(res1);\n for (int i = 0; i < 30; i++) {\n char[] res2 = String.valueOf(1 << i).toCharArray();\n Arrays.sort(res2);\n if (Arrays.equals(res1, res2)) return true;\n }\n return false;\n }\n}\n```\n\n---\n\n#### ***C++ Code:***\n\nThe best result for the code below is **0ms / 5.8MB** (beats 100% / 99%).\n```c++\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n string res1 = to_string(N);\n sort(res1.begin(), res1.end());\n for (int i = 0; i < 30; i++) {\n string res2 = to_string(1 << i);\n sort(res2.begin(), res2.end());\n if (res1 == res2) return true;\n }\n return false;\n }\n};\n``` | 21 | 7 | [] | 2 |
reordered-power-of-2 | ✅ Simple & Easy w/ Explanation | beats 100% | Shortest Clean Code | simple-easy-w-explanation-beats-100-shor-kc1u | Solution - I (Counting Digits Frequency)\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than 10^9 are equal. In our case, | archit91 | NORMAL | 2021-03-21T09:15:32.993156+00:00 | 2021-03-21T14:49:03.454819+00:00 | 890 | false | ***Solution - I (Counting Digits Frequency)***\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than `10^9` are equal. In our case, we need to check for all powers of 2 from `2^0` to `2^29` and if any of them matches with digits in `N`, return true.\n\n```\n// counts frequency of each digit in given number N and returns it as vector\nvector<int> countDigits(int N){\n\tvector<int>digitsInN(10);\n\twhile(N)\n\t\tdigitsInN[N % 10]++, N /= 10;\n\treturn digitsInN;\n}\nbool reorderedPowerOf2(int N) {\n\tvector<int> digitsInN = countDigits(N); // freq of digits in N\n\t// powOf2 goes from 2^0 to 2^29 and each time freq of digits in powOf2 is compared with digitsInN\n\tfor(int i = 0, powOf2 = 1; i < 30; i++, powOf2 <<= 1)\n\t\tif(digitsInN == countDigits(powOf2)) return true; // return true if both have same frequency of each digits\n\treturn false;\n}\n```\n\n**Time Complexity :** **`O(logn)`**, where `n` is maximum power of 2 for which digits are counted (2^30). More specifically the time complexity can be written as `O(logN + log2 + log4 + ... + log(2^30))` which after ignoring the constant factors and lower order terms comes out to `O(logn)`.\n**Time Complexity :** **`O(1)`**. We are using vector to store digits of `N` and powers of 2 but they are taking constant space and don\'t depend on the input `N`.\n\n---------\n---------\n\n***Solution - II (Convert to string & sort)***\n\nWe can convert `N` to string, sort it and compare it with every power of 2 by converting and sorting that as well.\n\n```\nbool reorderedPowerOf2(int N) {\n\tstring n = to_string(N);\n\tsort(begin(n), end(n));\n\tfor(int i = 0, powOf2 = 1; i < 30; i++, powOf2 <<= 1){\n\t\tstring pow2_str = to_string(powOf2);\n\t\tsort(begin(pow2_str), end(pow2_str));\n\t\tif(n == pow2_str) return true; \n\t}\n\treturn false;\n}\n```\n\n-------\n\nBoth solutions have the same run-time -\n\n\n\n-------\n------- | 19 | 2 | ['C'] | 0 |
reordered-power-of-2 | [Python] Find anagram, explained | python-find-anagram-explained-by-dbabich-ucp0 | 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. | dbabichev | NORMAL | 2021-03-21T08:22:36.964596+00:00 | 2021-03-21T08:22:36.964626+00:00 | 918 | false | 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!** | 18 | 2 | [] | 2 |
reordered-power-of-2 | ✅ From brute force to optimziation | Fully Explained | from-brute-force-to-optimziation-fully-e-8f3q | In this post, I shared my full thought process behind the question, and how I arrived at the optimal solution.\n\nIn contrast to just posting the answer, I try | nadaralp | NORMAL | 2022-08-26T06:07:37.529560+00:00 | 2022-08-26T06:12:28.543107+00:00 | 1,040 | false | In this post, I shared my full thought process behind the question, and how I arrived at the optimal solution.\n\nIn contrast to just posting the answer, I try to teach and show how to tackle problems and arrive progressively at the optimal solution, instead of memorizing them :)\n\n<hr />\n\nThe problem states that we are given an integer `n` and we can rearrange it in any order, except leading zero. And we need to check whether we can arrive at a valid power of 2.\n\nIn such questions, it\'s very important to look at the **constraints** because a lot of times it can contradict/hint toward specific solutions. In our case `1 <= n <= 10^9`\n\nGiven the constraints, we know that we can have at most 10 digits in n. So generating all permutations will cost us n!, which is **10!** => **3,628,800** (A little less because 0 is invalid in the first position. But that\'s an upper bound)\n\nAlso, we know that a 32-bit integer has 31 powers of 2. You can just shift the active bit to the left. (1 bit it taken for the sign)\n\nSo the initial idea can be to generate a set containing all the powers of 2, and to generate a set of all the permutations, and then check whether there is an element that is intersecting between both sets.\n\n# Naive brute force\n\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n int32_powers_of_two = set()\n for i in range(31):\n int32_powers_of_two.add(1<<i)\n \n n_numbers = []\n while n > 0:\n n_numbers.append(n % 10)\n n //= 10\n \n permutations = set()\n def generate_permutations(cur_permutation, options):\n if not options:\n permutations.add(int(cur_permutation))\n return\n \n for i in range(len(options)):\n if cur_permutation == "" and options[i] == 0: continue\n generate_permutations(cur_permutation + str(options[i]), [*options[:i], *options[i+1:]])\n \n generate_permutations("", n_numbers)\n return permutations.intersection(int32_powers_of_two)\n```\n\nThat will TLE on the last test cases. Let\'s optimize\n\n# Optimization\n\nOne observation that we can make is that we don\'t need to generate all the permutations for n. \n\nLet\'s say `n` is `4210`\n\nIt\'s enough for us to look at the powers of two that have 4 digits. i.e. [1024, 2048, 4096, 8192]\n\nTake a look, can `n` be reordered to a power of 2? how would you know that efficiently?\n\nWhenever you are asked about ordering/shuffling and equality, think about sorting. Sorting will represent the lexicographical order, and if both lexicographical orders are equal, you can reshuffle A to get B.\n\nIf we sort `n` = `4210` -> `0124`\nIf we sort `1024` (a power of 2) -> `0124`\n\nBoth are equal, hence we can reorder n to get a power of two.\n\n# Algorithm\n1. We will generate all permutations of 2 within the 32-bit integer range, but store them in buckets relevant to their digit count. This will allow us to look at the powers of 2 that have the same digit count as n\n2. We will sort `n` (transform to string and sort) and compare against all powers of 2 with the same digit count sorted.\n3. If we find the same lexicographical order, we can reorder to a valid power of 2. \n4. If non-matched, we return false after the iteration.\n\n\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n buckets = [[] for _ in range(11)]\n for i in range(31):\n power_of_two = 1<<i\n digits_count = math.floor(math.log10(power_of_two)) + 1\n buckets[digits_count].append(power_of_two)\n \n n_str_sorted = "".join(sorted(str(n)))\n n_digits_count = math.floor(math.log10(n)) + 1\n for power_of_two in buckets[n_digits_count]:\n if n_str_sorted == "".join(sorted(str(power_of_two))):\n return True\n return False\n```\n\n# Further notes\n* Instead of sorting you could also count the character frequency and check whether any power of 2 has the same count character count as `n`\n* Feel free to add a comment with the code in a different language so I\'ll add them to the post and mention your name.\n\n<hr />\nHave a great day!\n\nIf you found this read helpful, please upvote.\nIt motivates me to do more of them, and also shows me that these posts are helpful for some folks.\n | 14 | 1 | ['Python'] | 2 |
reordered-power-of-2 | Clean and Easy to Understand digits Anagram | clean-and-easy-to-understand-digits-anag-huzz | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int i = 0, num = 1; i < 32; i++, num <<= 1)\n if(Arrays.equals(digitFr | i18n | NORMAL | 2021-03-21T11:52:53.376726+00:00 | 2021-03-21T11:52:53.376767+00:00 | 816 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int i = 0, num = 1; i < 32; i++, num <<= 1)\n if(Arrays.equals(digitFreq(N), digitFreq(num)))\n return true;\n \n return false;\n }\n \n private int[] digitFreq(int N) {\n int[] f = new int[10];\n while(N > 0) {\n f[N % 10]++;\n N /= 10;\n }\n \n return f;\n }\n}\n``` | 14 | 4 | [] | 0 |
reordered-power-of-2 | C++ 0ms beats 100% | c-0ms-beats-100-by-soundsoflife-f0eo | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n set<string> si = {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", " | soundsoflife | NORMAL | 2018-08-13T11:23:42.450612+00:00 | 2018-09-02T01:17:02.330712+00:00 | 1,076 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n set<string> si = {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", "0248", "0469", "1289",\n "13468", "23678", "35566", "011237", "122446", "224588", "0145678", "0122579", "0134449",\n "0368888", "11266777", "23334455", "01466788", "112234778", "234455668", "012356789",\n };\n string t = to_string(N);\n sort(t.begin(), t.end());\n return si.count(t) > 0;\n }\n};\n``` | 14 | 5 | [] | 1 |
reordered-power-of-2 | JAVA Naive Backtracking 15 lines | java-naive-backtracking-15-lines-by-cara-mm9w | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] ca=(N+"").toCharArray();\n return helper(ca, 0, new boolean[ca.length]) | caraxin | NORMAL | 2018-07-15T03:01:41.591307+00:00 | 2018-09-11T09:38:32.034219+00:00 | 1,753 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] ca=(N+"").toCharArray();\n return helper(ca, 0, new boolean[ca.length]);\n }\n public boolean helper(char[] ca, int cur, boolean[] used){\n if (cur!=0 && (cur+"").length()==ca.length){\n if (Integer.bitCount(cur)==1) return true;\n return false;\n }\n for (int i=0; i<ca.length; i++){\n if (used[i]) continue;\n used[i]=true;\n if (helper(ca, cur*10+ca[i]-\'0\', used)) return true;\n used[i]=false;\n }\n return false;\n }\n}\n```\nIt would be faster if you use memo to prune.\n```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n char[] ca=(N+"").toCharArray();\n return helper(ca, 0, new boolean[ca.length], new HashSet<Integer>());\n }\n public boolean helper(char[] ca, int cur, boolean[] used, HashSet<Integer> vis){\n if (!vis.add(cur)) return false;\n if (cur!=0 && (cur+"").length()==ca.length){\n if (Integer.bitCount(cur)==1) return true;\n return false;\n }\n for (int i=0; i<ca.length; i++){\n if (used[i]) continue;\n used[i]=true;\n if (helper(ca, cur*10+ca[i]-\'0\', used, vis)) return true;\n used[i]=false;\n }\n return false;\n }\n}\n``` | 13 | 2 | [] | 1 |
reordered-power-of-2 | JAVA || Easy Solution Using HashSet | java-easy-solution-using-hashset-by-shiv-x7f0 | \tPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n Set<Long> two = new HashSet<>();\n for (int i = | shivrastogi | NORMAL | 2022-08-26T02:59:52.577941+00:00 | 2022-08-26T02:59:52.577971+00:00 | 1,772 | false | \tPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n Set<Long> two = new HashSet<>();\n for (int i = 1; i <= (int)1e9; i <<= 1){\n two.add(transform(i));\n }\n\n return two.contains(transform(n));\n }\n\n private long transform(int n){\n long sum = 0;\n while(n > 0){\n int d = n % 10;\n sum += 1L << (d*3);\n n /= 10;\n }\n\n return sum;\n }\n}\n``` | 12 | 1 | ['Java'] | 7 |
reordered-power-of-2 | Simple Python check upto 2 power 30 | simple-python-check-upto-2-power-30-by-c-szc0 | \n def reorderedPowerOf2(self, N):\n c1 = Counter(str(N))\n for i in range(30):\n n = int(math.pow(2, i))\n if Counter(st | Cubicon | NORMAL | 2018-07-15T03:01:55.089953+00:00 | 2018-10-09T05:04:41.496251+00:00 | 745 | false | ```\n def reorderedPowerOf2(self, N):\n c1 = Counter(str(N))\n for i in range(30):\n n = int(math.pow(2, i))\n if Counter(str(n)) == c1: return True\n return False\n``` | 11 | 1 | [] | 0 |
reordered-power-of-2 | C++ Easy Solution of Vector | c-easy-solution-of-vector-by-conquistado-qint | \nclass Solution {\npublic:\n vector<int> Helper(long n){\n vector<int>num(10);\n \n while(n){\n num[n%10]++;\n n= | Conquistador17 | NORMAL | 2022-08-26T02:46:36.943937+00:00 | 2022-08-26T02:46:36.943977+00:00 | 1,782 | false | ```\nclass Solution {\npublic:\n vector<int> Helper(long n){\n vector<int>num(10);\n \n while(n){\n num[n%10]++;\n n=n/10;\n }\n return num;\n }\n bool reorderedPowerOf2(int n) {\n vector<int>v=Helper(n);\n for(int i=0;i<31;i++){\n if(v==Helper(1<<i)){\n return true;\n }\n }\n return false;\n }\n};\n```\n# **Please share and Upvote it keeps me motivated** | 10 | 0 | ['C', 'C++'] | 4 |
reordered-power-of-2 | Python 27 ms (faster than 100%), new idea to improve other's solutions | python-27-ms-faster-than-100-new-idea-to-bs70 | Like others solutions, i use the same idea of counting the digits and then compare with digits of candidates: 1, 2, 4, 8, 16, 32, 64 ... 2^30.\nBut i noticed th | Splish-Splash | NORMAL | 2022-08-26T01:52:29.755772+00:00 | 2022-08-26T21:10:07.605063+00:00 | 925 | false | Like others solutions, i use the same idea of counting the digits and then compare with digits of candidates: ```1, 2, 4, 8, 16, 32, 64 ... 2^30```.\nBut i noticed that if our input is for example ```251``` we need to compare it only with power of 2 numbers that have exact 3 digits: ```128, 256, 512```, but how can we find out what numbers we need?\nLet\'s look for numbers that are powers of 2, their length(number of digits) and their power:\n```\nnumbers: 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192\nlength: 1 1 1 1 2 2 2 3 3 3 4 4 4 4 \npower: 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n```\nLet\'s see the pattern between ```length``` and ```power```:\nIf length of number is 1, power lies between 0 and 3, if length is 2 , power lies between 4 and 6 and etc.\nSo all we need is to find the formula to know in what boundaries numbers lie.\nFirst of all what i thought is that power lies in ```((length - 1) * 3 + 1, length * 3 + 1)```, for example for ```length = 2``` range will be ```range(4, 7) = (4, 5, 6)``` is what we needed, but this formula doesn\'t work for ```length = 1, 4, 7 etc```, because every third length(or every 10th power) there are 4 numbers with this length, that ruins the formula, so i thought "okay, what if we will add 1 every time when we our numbers length reaches 1, 4, 7 etc...", or in another words: ```add length // 3```, but now our length of range will always be 4, that is still better than 30.\nSo now our formula for range is ```((length - 1) * 3 + length // 3, length * 3 + length // 3 + 1)```, maybe there\'s a way to simplify the formula, but i think it\'s fine, so the final code is:\n```python\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n from collections import Counter\n length = len(str(n))\n c = Counter(str(n))\n for i in range((length-1) * 3 + length // 3, length * 3 + length // 3 + 1):\n candidate = str(1 << i)\n if c == Counter(candidate):\n return True\n return False\n```\n\nIf we replace the Counter with sorted, it can be even faster:\n```python\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n length = len(str(n))\n c = sorted(str(n))\n for i in range((length-1) * 3 + length // 3, length * 3 + length // 3 + 1):\n if c == sorted(str(1 << i)):\n return True\n return False\n```\n\n\n```\nP.S. The formula was obtained by trial and error, \nbut i came up with the main idea with connection length and power.\n```\n\n```\nP.P.S. Feel free to ask about something if it\'s unclear, \nwrite an improve ment if you have an idea, \nor point on mistakes(including english) :)\n```\n\n | 9 | 0 | ['Math', 'Sorting', 'Python'] | 6 |
reordered-power-of-2 | Python/Go O(log n) by digit-occurrence mapping [w/ Comment] | pythongo-olog-n-by-digit-occurrence-mapp-nz9y | For example:\n\nGiven power of 2 = 2 ^ 6 = 64\n\n64 => {6: 1, 4: 1}\n6 shows up one time\n4 shows up one time\n\n---\n\nN=46 or N=64 return true because their d | brianchiang_tw | NORMAL | 2021-03-21T08:27:13.881918+00:00 | 2021-03-23T12:59:29.456579+00:00 | 628 | false | For example:\n\nGiven power of 2 = 2 ^ 6 = 64\n\n64 => {6: 1, 4: 1}\n6 shows up one time\n4 shows up one time\n\n---\n\nN=46 or N=64 return **true** because their **digit - occurrence mapping** are the same with 64\n\n46 => {4: 1, 6: 1}\n4 shows up one time\n6 shows up one time\n\n64 => {6: 1, 4: 1}\n6 shows up one time\n4 shows up one time\n\n---\n\n**Implementation** by digit - occurrence mapping\n\nPython:\n\n```\nclass Solution:\n def reorderedPowerOf2(self, N: int) -> bool:\n \n # digit <-> occurrence mapping of N\n signature_of_N = Counter(str(N))\n \n \n # check each possible power of 2\n for i in range(32):\n \n # get power of 2 by bitwise operation\n power_of_2 = 1 << i\n \n if Counter( str(power_of_2) ) == signature_of_N:\n \n # Accept if at least one power of 2\'s mapping is the same with N\'s mapping\n return True\n \n # Reject otherwise\n return False\n```\n\n---\n\n**Implementation** by digit - occurrence mapping based on recursion and decimal representation\n\nPython:\n\n```\nclass Solution:\n def reorderedPowerOf2(self, N: int) -> bool:\n \n def make_signature(n: int):\n \n\t\t\t## base case\n if n == 0:\n return 0\n \n\t\t\t\n\t\t\t## general case\n\t\t\t\n leading, remaining = divmod(n, 10)\n return make_signature(leading) + ( 10 ** remaining )\n \n # ---------------------------------------------------------\n \n signature_of_N = make_signature(N)\n \n\t\t# check each possible power of 2\n for i in range(32):\n \n\t\t\t# get power of 2 by bitwise operation, and check signature\n if make_signature( 1 << i ) == signature_of_N:\n\t\t\t\n\t\t\t\t# Accept if at least one power of 2\'s signature is the same with N\'s signature\n return True\n \n\t\t# Reject otherwise\n return False\n```\n\n---\n\n**Implementation** by digit - occurrence mapping based on recursion and decimal representation\n\nGo:\n\n```\nfunc reorderedPowerOf2(N int) bool {\n \n var makeSignature func(n int) int\n \n makeSignature = func(n int) int {\n \n if n == 0{\n // base case\n return 0\n }\n \n // general case\n leading, remaining := n / 10, n % 10\n return makeSignature( leading ) + int( math.Pow(10, float64(remaining) ) )\n \n }\n \n // -----------------------------------------------------\n \n signatureN := makeSignature( N )\n \n // check each possible power of 2\n for i := 0 ; i < 32 ; i++ {\n \n if makeSignature( 1 << i ) == signatureN{\n \n // Accept if at least one power of 2\'s signature is the smae with N\'s\n return true\n }\n \n }\n \n // Reject otherwise\n return false\n}\n```\n\n---\n\nReference:\n\n[1] [Python official docs about specialized dictionary Counter( ... )](https://docs.python.org/3/library/collections.html#collections.Counter)\n\n[2] [Python official docs about bitwise operation](https://wiki.python.org/moin/BitwiseOperators) | 9 | 0 | ['Recursion', 'Python', 'Go', 'Python3'] | 1 |
reordered-power-of-2 | Possibly fastest C++ solution using Multiset, 0ms runtime. | possibly-fastest-c-solution-using-multis-5fxa | So, the idea is very simple:\n1. Convert N into a multiset of its digits, for an example, if N = 426412 then the multiset will contain {1, 2, 2, 4, 4, 6}.\n2. N | mbanik | NORMAL | 2018-07-16T05:24:20.154604+00:00 | 2018-07-16T05:24:20.154604+00:00 | 1,085 | false | **So, the idea is very simple:**\n1. Convert `N` into a multiset of its digits, for an example, if `N = 426412` then the multiset will contain `{1, 2, 2, 4, 4, 6}`.\n2. Now, we will generate some 2\'s power and will convert them into another multiset as well, **if both multiset are same**, function will return **true**\n3. To speed up the process we don\'t need to find all `2`\'s power. In fact, it will depent on `N`, if `N` has `6` digits, I compute `2^12 to 2^20`, the above number is `2^18`, when both set matches, we just return true.\n\n```\nprivate: \n multiset<int> convert(int num) { // this function converts a number into a multiset of its digit.\n multiset<int> allDigit;\n while(num) { allDigit.insert(num%10); num /= 10; }\n return allDigit;\n }\n \npublic:\n bool reorderedPowerOf2(int N) {\n \n if(N<10) { // for single digit\n if (N==1 || N==2 || N==4 || N==8) return true;\n return false;\n }\n\n multiset<int> digitN;\n int num = N, cc=0, powerOf2=8;\n\n while(num) { digitN.insert(num%10); num /= 10; cc++;}\n\n for(int i=4; i <= 4*cc; i++) { // number of digit in decimal <= 4 * number of digit in binary\n powerOf2 *= 2;\n multiset<int> digitNum = convert(powerOf2);\n if(digitNum == digitN) return true;\n }\n return false;\n }\n``` | 9 | 1 | [] | 3 |
reordered-power-of-2 | [LeetCode The Hard Way] Easy Sorting with Explanation | leetcode-the-hard-way-easy-sorting-with-ihmq6 | Please check out LeetCode The Hard Way for more solution explanations and tutorials. If you like it, please give a star and watch my Github Repository.\n\n---\n | __wkw__ | NORMAL | 2022-08-26T03:12:47.027856+00:00 | 2022-08-26T03:12:47.027898+00:00 | 559 | false | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. If you like it, please give a star and watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way).\n\n---\n\n```cpp\nclass Solution {\npublic:\n string sortStr(int n) {\n // since the input is an integer,\n // we convert it to a string first\n string t = to_string(n);\n // use STL to sort\n sort(t.begin(), t.end());\n // return the string\n return t;\n }\n \n // the idea is to sort `n` and compare all sorted power of two\n // if they are matched, then it means they can be reordered to each other\n bool reorderedPowerOf2(int n) {\n // since the sorted string of n is always same\n // so we convert it here instead of doing it in the loop\n string s = sortStr(n);\n for (int i = 0; i < 30; i++) {\n // power of 2 = 1 << i\n // we sort each power of 2 string\n string t = sortStr(1 << i);\n // and compare with `s`\n // if they are matched, then return true\n if (s == t) return true;\n }\n // otherwise it is not possible to reorder to a power of 2\n return false;\n }\n};\n``` | 6 | 0 | ['Bit Manipulation', 'C', 'Sorting', 'C++'] | 2 |
reordered-power-of-2 | 🗓️ Daily LeetCoding Challenge August, Day 26 | daily-leetcoding-challenge-august-day-26-cr6b | This problem is the Daily LeetCoding Challenge for August, Day 26. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2022-08-26T00:00:22.161205+00:00 | 2022-08-26T00:00:22.161290+00:00 | 2,923 | false | This problem is the Daily LeetCoding Challenge for August, Day 26.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please create a new post in the discuss section and provide
- **Detailed Explanations**: Describe the algorithm you used to solve this problem. Include any insights you used to solve this problem.
- **Images** that help explain the algorithm.
- **Language and Code** you used to pass the problem.
- **Time and Space complexity analysis**.
---
**📌 Do you want to learn the problem thoroughly?**
Read [**⭐ LeetCode Official Solution⭐**](https://leetcode.com/problems/reordered-power-of-2/solution) to learn the 3 approaches to the problem with detailed explanations to the algorithms, codes, and complexity analysis.
<details>
<summary> Spoiler Alert! We'll explain these 2 approaches in the official solution</summary>
**Approach 1:** Permutations
**Approach 2:** Counting
</details>
If you're new to Daily LeetCoding Challenge, [**check out this post**](https://leetcode.com/discuss/general-discussion/655704/)!
---
<br>
<p align="center">
<a href="https://leetcode.com/subscribe/?ref=ex_dc" target="_blank">
<img src="https://assets.leetcode.com/static_assets/marketing/daily_leetcoding_banner.png" width="560px" />
</a>
</p>
<br> | 6 | 0 | [] | 48 |
reordered-power-of-2 | [JavaScript] Easy to understand - 4 solutions | javascript-easy-to-understand-4-solution-0an5 | For this problem, there are 2 main strategies to solve it:\n- One is following the rules in the description and try every possible option.\n- Another one is to | poppinlp | NORMAL | 2021-03-22T08:54:45.809266+00:00 | 2021-03-22T08:54:45.809292+00:00 | 415 | false | For this problem, there are 2 main strategies to solve it:\n- One is following the rules in the description and try every possible option.\n- Another one is to try to find a way to serialize the number and check whether the serialization for `N` matches any serialization of power of 2.\n\n## SOLUTION 1\n\nFirst, we try the most straight forward solution - validate every reordered sequence of `N` and check if it\'s the power of 2.\n\n```js\nconst set = new Set();\nfor (let cur = 1; cur < 10 ** 9; cur <<= 1) {\n set.add(String(cur));\n}\n\nconst validate = (left, cur = "") => {\n if (left.length === 1) return set.has(cur + left[0]);\n for (let i = 0; i < left.length; ++i) {\n const next = left.slice(0, i) + left.slice(i + 1);\n if (validate(next, cur + left[i])) return true;\n }\n return false;\n};\n\nconst reorderedPowerOf2 = (n) => validate(String(n));\n```\n\n## SOLUTION 2\n\nWe could find out all the possible sequences for the power of 2 between 1 and 10 ** 9 first. And then just check the mapping for the result.\n\n```js\nconst set = new Set();\n\nconst permute = (left, cur = "") => {\n if (left.length === 1) {\n set.add(Number(cur + left[0]));\n return;\n }\n for (let i = 0; i < left.length; ++i) {\n if (left[i] === "0" && cur.length === 0) continue;\n const next = left.slice(0, i) + left.slice(i + 1);\n permute(next, cur + left[i]);\n }\n};\n\nfor (let cur = 1; cur < 10 ** 9; cur <<= 1) {\n permute(String(cur));\n}\n\nconst reorderedPowerOf2 = (n) => set.has(n);\n```\n\n## SOLUTION 3\n\nThis solution follows the second strategy. We achieve serialization by counting the occurrences of each number.\n\n```js\nconst set = new Set();\n\nconst serialize = str => {\n const count = new Uint8Array(10);\n const BASE = 48;\n for (let i = 0; i < str.length; ++i) {\n ++count[str.charCodeAt(i) - BASE];\n }\n return count.join(\':\');\n};\n\nfor (let cur = 1; cur < 10 ** 9; cur <<= 1) {\n set.add(serialize(String(cur)));\n}\n\nconst reorderedPowerOf2 = (n) => set.has(serialize(String(n)));\n```\n\n## SOLUTION 4\n\nHere we use a more efficient serialization approach.\nSince the range is `[1, 10 ** 9]`, so for every number, the occurrences must small than 10, which means we could use a number to represent the serialization value. For example, `4510` means there are 4 number 4, 5 number 3, 1 number 2 and 0 number 1.\n\n```js\nconst set = new Set();\n\nconst serialize = num => {\n let val = 0;\n while (num >= 1) {\n val += 1 << num % 10;\n num /= 10;\n }\n return val;\n};\n\nfor (let cur = 1; cur < 10 ** 9; cur <<= 1) {\n set.add(serialize(cur));\n}\n\nconst reorderedPowerOf2 = (n) => set.has(serialize(n));\n``` | 6 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | [C++] Linear Time, Constant Space Solution Explained, 100% Time, 100% Space | c-linear-time-constant-space-solution-ex-87k4 | Great problem to tackle and, since it was pretty straightforward, I gave myself a few extra challenges:\n no conversion to string (that will not look cool to mo | ajna | NORMAL | 2021-03-21T10:23:05.397443+00:00 | 2021-03-21T13:30:29.634109+00:00 | 619 | false | Great problem to tackle and, since it was pretty straightforward, I gave myself a few extra challenges:\n* no conversion to string (that will not look cool to most interviewers anyway);\n* no sorting;\n* getting there with constant space.\n\nAnd it looks like I did it \uD83C\uDF8A !\n\nIn order to proceed, first of all I declared as a `static constexpr` a 2D array with all the powers of 2 up to the given limit (`9` digits), grouped by number of digits, so that I could have a smoother lookup later.\n\nIn the main function, we will declare 2 support variables:\n* `digits` is an array of `9` elements (again, the maximum we might have to consider;\n* `pos` is a pointer that will tell us where to write or up to where to read in `digits`, preset to `0`.\n\nWe will then proceed to destructure `n` into its base digits, proceeding until it is reduced to `0` and:\n* assign its quotient and remainder to the aptly named `qr`;\n* store the remainder in `digits`, while also increasing `pos` by `1`;\n* update `n` to be the quotient - ie: functionally shaving off the least significant/leftmost digit that we just store.\n\nOnce done, we will call `verifyDigits` with all the non-`0` values that we have in `powers[pos]` (ie: all the powers of 2 we pre-stored), returning `true` if anyone of them matches the content of digits (ie: the initial number was an "anagram" of any power of 2 with the same amount of digits).\n\n`verifyDigits` takes 3 parameters (our array/pointer `digits`, `pos` which doubles now as the size of `digits` and `n`, the pre-stored power of 2 to verify) and:\n* declare a support variable `check` as an array of `10` elements, all preset to `0`;\n* increase each matching cell of `check` by `1` for each element in `digits` up to `pos` - so, for example, if we had `digits = {3, 5, 6, 6, 5}`, `check` would be `{0, 0, 0, 1, 0, 2, 2, 0, 0, 0}`;\n* proceed to destructure `n` in a similar fashion to what we did before and:\n\t* put quotient and remainder into `qr`;\n\t* return `false` if any cell of `check` matching the remainder (ie: the least significant digits) ends up being reduced below `0`;\n\t* update `n` to be the quotient, shaving off again the least significant digit and moving on;\n* return `true` if we reach the end of the loop, since we successfully reduced `pos` elements in `check` without any of them going below `0`, which implies a perfect match!\n\nIf we are back in the main function, we will then return `false` at this point, since all the `digits` from the original `n` could not be used to make any known power of 2.\n\nThe code:\n\n```cpp\n// precomputed values of powers, grouped by number of digits\nstatic constexpr int powers[10][4] = {{}, {1, 2, 4, 8}, {16, 32, 64}, {128, 256, 512}, {1024, 2048, 4096, 8192}, {16384, 32768, 65536}, {131072, 262144, 524288}, {1048576, 2097152, 4194304, 8388608}, {16777216, 33554432, 67108864}, {134217728, 268435456, 536870912}};\n\nclass Solution {\n bool verifyDigits(int *digits, int pos, int n) {\n // support variables\n int check[10] = {};\n // preparing check\n for (int i = 0; i < pos; i++) check[digits[i]]++;\n // destructuring n into its digits\n while (n) {\n auto qr = div(n, 10);\n // verifying if the matching least significant digit can be used\n if (--check[qr.rem] < 0) return false;\n // updating n\n n = qr.quot;\n }\n return true;\n }\npublic:\n bool reorderedPowerOf2(int n) {\n // support variables\n int digits[9], pos = 0;\n // destructuring n into its digits\n while (n) {\n auto qr = div(n, 10);\n // storing the least significant digit of n\n digits[pos++] = qr.rem;\n // updating n\n n = qr.quot;\n }\n // checking if we have a match for any known power of 2 with the same amount of digits\n for (int n: powers[pos]) if (n && verifyDigits(digits, pos, n)) return true;\n return false;\n }\n};\n``` | 6 | 2 | ['C', 'C++'] | 1 |
reordered-power-of-2 | C++ | Efficient Solution | Easy | c-efficient-solution-easy-by-ansaine-f1km | \nbool reorderedPowerOf2(int n) {\n \n if(n==1)\n return true;\n \n string num = to_string(n);\n sort(num.begin(),num.end());\n \n | Ansaine | NORMAL | 2022-08-26T14:29:53.580480+00:00 | 2022-08-26T14:29:53.580514+00:00 | 330 | false | ```\nbool reorderedPowerOf2(int n) {\n \n if(n==1)\n return true;\n \n string num = to_string(n);\n sort(num.begin(),num.end());\n \n unordered_map<string,int> powers;\n \n //creating all 0 to 29 possible powers of 2;\n for(int i =0 ; i<=29; i++){\n string str = to_string((int)pow(2,i)); //pow function returns float so we need to convert\n sort(str.begin(),str.end());\n powers[str] = 1;\n } \n \n if(powers[num]==1)\n return 1;\n else\n return 0;\n \n}\n};\n``` | 5 | 0 | ['C'] | 0 |
reordered-power-of-2 | C++ | Easy solution | c-easy-solution-by-ansaine-z28d | \nclass Solution {\npublic:\n \nbool isPowerOfTwo(int n) { \n if(n==0)\n return 0;\n \n if(ceil(log2(n)) == floor(log2(n)))\n | Ansaine | NORMAL | 2022-08-26T13:50:10.683491+00:00 | 2022-08-26T13:50:10.683530+00:00 | 215 | false | ```\nclass Solution {\npublic:\n \nbool isPowerOfTwo(int n) { \n if(n==0)\n return 0;\n \n if(ceil(log2(n)) == floor(log2(n)))\n return 1;\n else\n return 0; \n}\n \n \nbool reorderedPowerOf2(int n) {\n \n string num = to_string(n);\n sort(num.begin(),num.end());\n \n do{ \n if(num[0]==\'0\') //edge case\n continue;\n\t\t\t\n if(isPowerOfTwo(stoi(num)))\n return 1; \n }while(next_permutation(num.begin(),num.end())); \n \n\treturn 0;\n}\n};\n``` | 5 | 0 | ['C', 'Probability and Statistics'] | 0 |
reordered-power-of-2 | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-a2v6 | Using Hashmap\n\n Time Complexity :- O(Constant * logN)\n\n Space Complexity :- O(Constant)\n\n\nclass Solution {\npublic:\n \n // function for checking i | __KR_SHANU_IITG | NORMAL | 2022-08-26T04:19:40.624782+00:00 | 2022-08-26T04:19:40.624826+00:00 | 346 | false | * ***Using Hashmap***\n\n* ***Time Complexity :- O(Constant * logN)***\n\n* ***Space Complexity :- O(Constant)***\n\n```\nclass Solution {\npublic:\n \n // function for checking is two numbers have identiacal digits\n \n bool is_possible(int num1, int num2)\n {\n vector<int> mp(10, 0);\n \n // increment the count of digits by num1 \n \n while(num1)\n {\n int r = num1 % 10;\n \n mp[r]++;\n \n num1 = num1 / 10;\n }\n \n // decrement the count of digits by num2\n \n while(num2)\n {\n int r = num2 % 10;\n \n mp[r]--;\n \n num2 = num2 / 10;\n }\n \n // check if both are idenical of not\n \n for(int i = 0; i < 10; i++)\n {\n if(mp[i] != 0)\n return false;\n }\n \n return true;\n }\n \n bool reorderedPowerOf2(int n) {\n \n // first of all find all the power of 2 <= 1e9 and store in power array\n \n int num = 1;\n \n vector<int> power;\n \n power.push_back(1);\n \n while(num * 2 <= 1e9)\n {\n power.push_back(num * 2);\n \n num = num * 2;\n }\n \n // compare the number with every element of power array, if any of them have the identical digits \n \n // then we can reorder the number to power of 2\n \n for(int i = 0; i < power.size(); i++)\n {\n if(is_possible(power[i], n))\n return true;\n }\n \n return false;\n }\n};\n``` | 5 | 0 | ['C', 'Counting', 'C++'] | 1 |
reordered-power-of-2 | python3 | easy understanding | sort | python3-easy-understanding-sort-by-h-r-s-hww6 | \nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n i, arr = 0, []\n v = 2**i\n while v <= 10**9: arr.append(sorted(str(v | H-R-S | NORMAL | 2022-08-26T01:55:08.837660+00:00 | 2022-08-26T01:55:08.837696+00:00 | 1,001 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n i, arr = 0, []\n v = 2**i\n while v <= 10**9: arr.append(sorted(str(v))); i+=1; v = 2**i\n return sorted(str(n)) in arr\n``` | 5 | 1 | ['Math', 'Sorting', 'Python3'] | 1 |
reordered-power-of-2 | Python My Soln | python-my-soln-by-lucasschnee-lm1z | class Solution:\n\n def reorderedPowerOf2(self, n: int) -> bool:\n n1 = sorted(str(n))\n \n for i in range(30):\n res = sorte | lucasschnee | NORMAL | 2022-08-26T01:30:16.032730+00:00 | 2022-08-26T01:30:16.032782+00:00 | 1,000 | false | class Solution:\n\n def reorderedPowerOf2(self, n: int) -> bool:\n n1 = sorted(str(n))\n \n for i in range(30):\n res = sorted(str(2 ** i))\n if res == n1:\n return True\n \n \n return False | 5 | 0 | ['Python', 'Python3'] | 6 |
reordered-power-of-2 | [Java] - count occurance of digits | java-count-occurance-of-digits-by-dark_w-hq87 | From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, | dark_warlord | NORMAL | 2021-03-21T07:53:09.423054+00:00 | 2021-03-21T07:53:09.423096+00:00 | 99 | false | From the problem description it is clear that we need to check whether N is a permutation of a power of 2. The approach is the following:\n\nIn the first step, we count the occurance of each digit (0-9) in N\n\nIn the second step, we go through each power of 2 (say, x). For each x, we do the following:\n1. Count the occurance of each digit in x\n2. We compare the occurance of digits in x with that of N. If we find a match, we return true.\n3. If we don\'t find a match for any x, we return false.\n\nFor example, for N = 83461, the counts will match for x = 16384 and thus we will return true. For, N = 10000, the counts will not match for any x, so we will return false.\n\n```\n\tpublic boolean reorderedPowerOf2(int N) {\n int[] dcountN = getDigitCount(N);\n \n for(int i = 0; i < 31; i++){\n int x = 1 << i, j;\n int[] dcountX = getDigitCount(x);\n \n for(j = 0; j < 10 && dcountN[j] == dcountX[j]; j++);\n\t\t\t/*if j becomes 10 after above loop, it means the counts\n\t\t\t of the digits are the same in x and N*/\n if(j == 10) return true;\n }\n \n return false;\n }\n \n private int[] getDigitCount(int x){\n int[] result = new int[10];\n while(x > 0){\n result[x % 10]++;\n x /= 10;\n }\n return result;\n } | 5 | 3 | [] | 0 |
reordered-power-of-2 | [python 3] | python-3-by-bakerston-mfk7 | \ndef reorderedPowerOf2(self, N: int) -> bool:\n c, l = collections.Counter(str(N)), len(str(N))\n n = 1\n while len(str(n)) <= l:\n | Bakerston | NORMAL | 2021-01-10T21:39:12.380397+00:00 | 2021-01-10T21:39:12.380442+00:00 | 102 | false | ```\ndef reorderedPowerOf2(self, N: int) -> bool:\n c, l = collections.Counter(str(N)), len(str(N))\n n = 1\n while len(str(n)) <= l:\n if collections.Counter(str(n)) == c:\n return True\n n *= 2\n return False\n``` | 5 | 0 | [] | 0 |
reordered-power-of-2 | One line python beats 70% | one-line-python-beats-70-by-mopriestt-tvnq | \nclass Solution:\n def reorderedPowerOf2(self, N):\n return sorted(str(N)) in [sorted(str(1<<i)) for i in range(33)]\n | mopriestt | NORMAL | 2018-09-21T15:54:17.908439+00:00 | 2018-10-01T02:31:42.726166+00:00 | 689 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, N):\n return sorted(str(N)) in [sorted(str(1<<i)) for i in range(33)]\n``` | 5 | 0 | [] | 2 |
reordered-power-of-2 | ⚡⚡ Lightining Fast | 🧠🧠 High IQ | 🦸♂️🦸♂️ Marvel Approach | lightining-fast-high-iq-marvel-approach-du4q8 | Logic?\n\nWe have used a special operation here " << " , which is know as binary left operator. The left operands value is moved left by the number of bits sp | sHadowSparK | NORMAL | 2022-08-26T18:45:47.122132+00:00 | 2022-08-26T19:25:04.205026+00:00 | 163 | false | **Logic?**\n\nWe have used a special operation here " **<<** " , which is know as **binary left operator**. The left operands value is moved left by the number of bits specified by the right operand.\n\nSo ,\n*1 = 00000000 00000000 00000000 00000001 = 1*\n*1 << 1 = 00000000 00000000 00000000 00000010 = 2*\n*1 << 8 = 00000000 00000000 00000001 00000000 = 256*\n\n***for e.g., 1<<6 will be 1(2^6)= 64***\n\n***So here we are just trying to store, 2 to the power i***\n\nHence, for each value of **i** in for loop it will give us the corresponding **power of 2** which we store in a string as digits!\n\n\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n \n //Create a string to store the number as individual digits\n string num = to_string(n);\n \n //Sort the string of digits\n sort(num.begin(), num.end());\n \n //It is given that n lies in range [ 1 <= n <= 10^9 ]\n //So, if n is a power of 2 it must exist between 2^0(=1) to 2^30(1073741824)\n \n //Hence, we loop from 0 to 29 and find all corresponding powers of 2\n \n for(int i = 0; i < 30; i++){\n \n //For each i, the respective power of 2 can be calculated as:\n //**Logic is discussed above**\n string powerOf2 = to_string(1 << i);\n \n //We again convert that number to string and sort its digits\n sort(powerOf2.begin(), powerOf2.end());\n \n //If the resulting sorted string of digits is equal to num string then return True\n if(num == powerOf2){\n \n return true;\n }\n }\n \n // Else, that number isn\'t a power of 2 and so return False\n return false;\n }\n};\n```\n\n**@Credits to @rahulvarma5297 and @divyamRai for the original answers!**\n\n\n\n\n\n | 4 | 0 | ['C'] | 0 |
reordered-power-of-2 | best JAVA solution | best-java-solution-by-ayushsharma57-1pvn | \nTC : Calculating the frequency Count for a no would be O(no of digits in N). Also,there could a case where it matches with 2^31 (last power of 2).So the compl | AyushSharma57 | NORMAL | 2022-08-26T16:13:02.193178+00:00 | 2022-08-26T16:15:38.882982+00:00 | 46 | false | \n**TC : Calculating the frequency Count for a no would be O(no of digits in N). Also,there could a case where it matches with 2^31 (last power of 2).So the complexity would be O(32*length(2^32) + O(no of digits in N)**\n```\nclass Solution { \n \n public boolean reorderedPowerOf2(int n) \n {\n\t\tint [] nFreq=digitFreq(n);\n \n for(int i=0;i<31;i++) //Within the integer range max power of 2 that lies is 2^31\n {\n int powerOf2=(int)Math.pow(2,i);\n int [] powerOf2FreqCount = digitFreq(powerOf2); \n if(compareFreq(nFreq,powerOf2FreqCount)) \n return true; \n }\n return false;\n }\n \n private boolean compareFreq (int []nFreq ,int []powerOf2FreqCount){\n boolean match=true;\n \n for(int i=0;i<10;i++){\n if(nFreq[i]!=powerOf2FreqCount[i])\n return false; \n }\n return true;\n }\n \n private int [] digitFreq(int num){\n int [] digitFreq=new int [10];\n while(num>0){\n digitFreq[num%10]++; //counting freq for each digit so here we extracted the last digit from number ( from right side )\n num /= 10; \n }\n return digitFreq;\n }\n}\n``` | 4 | 0 | ['Array'] | 0 |
reordered-power-of-2 | one easy way to solve | one-easy-way-to-solve-by-jahidaladin-omfv | \nvar reorderedPowerOf2 = function(n) {\n let str = n.toString();\n let initialString = str.split(\'\').sort().join(\'\');\n \n \n for(let i=0; i | jahidaladin | NORMAL | 2022-08-26T13:20:05.558610+00:00 | 2022-08-26T13:20:05.558651+00:00 | 291 | false | ```\nvar reorderedPowerOf2 = function(n) {\n let str = n.toString();\n let initialString = str.split(\'\').sort().join(\'\');\n \n \n for(let i=0; i<30; i++){\n let tempString = (1<<i).toString();\n let finalString = tempString.split(\'\').sort().join(\'\');\n if(initialString===finalString){\n return true\n }\n }\n return false\n}\n```\n | 4 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | 100.00% of c++|| 2 approach ||Using Map and sorting || optimise space | 10000-of-c-2-approach-using-map-and-sort-aok8 | 1st approach using only sorting function\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) { \n vector<string>v;\n \n for(int | Akash-Jha | NORMAL | 2022-08-26T09:06:28.056690+00:00 | 2022-08-26T09:07:55.911238+00:00 | 351 | false | **1st approach using only sorting function**\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) { \n vector<string>v;\n \n for(int i=0;i<=30;i++){\n int p = pow(2 , i);\n v.push_back(to_string(p));\n }\n \n for(int i=0;i<=30;i++){\n sort(v[i].begin() , v[i].end());\n }\n \n string s = to_string(n);\n sort(s.begin() , s.end());\n \n for(int i=0;i<=30;i++){\n if(v[i]==s) return true;\n }\n return false;\n }\n}; \n```\n\n**2nd approach using map**\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) { \n\n int x = pow(10 , 9);\n map<int ,vector<int>>word;\n for(int i=1;i<=x;i=i*2){\n int k =i;\n vector<int>v(10 , 0);\n while(k){\n int l = k%10;\n v[l]++;\n k=k/10;\n }\n word[i]=v;\n }\n \n vector<int> v(10 , 0);\n while(n){\n int l = n%10;\n v[l]++;\n n=n/10;\n }\n \n for(int i=1;i<=x;i=i*2){\n \n vector<int> m=word[i];\n bool flag=0;\n for(int j=0;j<=9;j++){\n if(v[j]!=m[j]){\n flag=1;\n }\n }\n if(flag==0){\n return 1;\n }\n }\n return 0; \n }\n}; \n```\n\n**If you found this solution helpful a upvote is highly appreciated** | 4 | 0 | ['C', 'Sorting'] | 1 |
reordered-power-of-2 | [C++] 0 ms, faster than 100.00% | c-0-ms-faster-than-10000-by-hououin__kyo-14ug | C++:\n\nvector<string> arr = {"0112344778","011237","0122579",\n"012356789","0124","0134449","0145678","01466788","0248",\n"0368888","0469","1","112234778","112 | Hououin__Kyouma | NORMAL | 2022-08-26T06:32:52.295426+00:00 | 2022-08-26T06:32:52.295541+00:00 | 219 | false | **C++:**\n```\nvector<string> arr = {"0112344778","011237","0122579",\n"012356789","0124","0134449","0145678","01466788","0248",\n"0368888","0469","1","112234778","11266777","122446",\n"125","128","1289","13468","16","2","224588","23","23334455",\n"234455668","23678","256","35566","4","46","8"};\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n return s == arr[lower_bound(arr.begin(),arr.end(),s)\n\t - arr.begin()];\n \n }\n};\n```\n\nStep 1: Convert each power of 2 (upto 30) to string and sort all strings. \nStep 2: Push the resultant strings to global vector `arr` in the sorted fashion.\n\nYour vector will look like something like this -\n```\n["0112344778","011237","0122579",\n"012356789","0124","0134449","0145678","01466788","0248",\n"0368888","0469","1","112234778","11266777","122446",\n"125","128","1289","13468","16","2","224588","23","23334455",\n"234455668","23678","256","35566","4","46","8"]\n```\n\nNow simply convert `n` to string `s`, sort it and apply binary search to find `s` in `arr`\nEg - \nn = 251\ns = "251"\nafter sorting : s = "125"\nfind index of "125" in `arr` and retrive the index\nhere index will be 16,\nNow simply check whether string exists or not by `arr[index]==s`\nreturn it ;)\n\n*Upvote if it helped you*\n\n | 4 | 0 | [] | 0 |
reordered-power-of-2 | Javascript | Easy to Understand | Fully explained | Power of 2 | Simple | javascript-easy-to-understand-fully-expl-vmei | \n//Main function\nvar reorderedPowerOf2 = function(n) {\n let arr = FindDigitMapArray(n);\n \n for(let i=0;i<31;i++){ //Till value of power of 2 is less tha | vivi13 | NORMAL | 2022-08-26T04:23:11.343974+00:00 | 2022-08-26T04:23:11.344028+00:00 | 420 | false | ```\n//Main function\nvar reorderedPowerOf2 = function(n) {\n let arr = FindDigitMapArray(n);\n \n for(let i=0;i<31;i++){ //Till value of power of 2 is less than 10^9 or 2^32 find all such power of 2\n let num = Math.pow(2,i);\n let twoArray = FindDigitMapArray(num);\n if(CheckTwoArraysAreEqual(arr,twoArray)) return true;\n }\n return false;\n}\n\n//Function to generate digit map\nvar FindDigitMapArray = function(n){ //For a given number it stores the count of digit on respective index.\n let arr = Array(10).fill(0);\n while(n>0){\n arr[n%10]+=1;\n n/=10;\n n=Math.floor(n);\n }\n return arr;\n}\n\n//Function to check if two arrays are equal\nvar CheckTwoArraysAreEqual = function(arr,twoArray){\n let count = 0;\n for(let i=0;i<10;i++){ //Check if digit map of both numbers are equal\n if(twoArray[i]==arr[i]){\n count++;\n }\n }\n if(count==10) return true;\n}\n``` | 4 | 0 | ['JavaScript'] | 0 |
reordered-power-of-2 | Java | Sort | java-sort-by-student2091-wx9g | We can do the hash thing or we can also just sort it.\nI think sorting is easier. \nJava\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n | Student2091 | NORMAL | 2022-08-26T04:05:06.242104+00:00 | 2022-08-26T04:05:14.380802+00:00 | 830 | false | We can do the hash thing or we can also just sort it.\nI think sorting is easier. \n```Java\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n for (int i = 0; i <= 30; i++){\n char[] a = (""+(1<<i)).toCharArray();\n char[] b = (""+n).toCharArray();\n Arrays.sort(a);\n Arrays.sort(b);\n if (Arrays.equals(a, b)){\n return true;\n }\n }\n return false;\n }\n}\n``` | 4 | 0 | ['Sorting', 'Java'] | 0 |
reordered-power-of-2 | C++ || Easy to Understand || Beginner Friendly | c-easy-to-understand-beginner-friendly-b-kb59 | \tbool check(string str)\n\t{\n\t\tint x = 0;\n\t\tfor(int i=0;i<str.size();i++)\n\t\t{\n\t\t\tx=x*10+(str[i]-\'0\');\n\t\t}\n\t\tint z = (x&(x-1));\n\t\tif(z== | viditgupta7001 | NORMAL | 2022-08-26T01:36:06.198883+00:00 | 2022-08-26T01:36:06.198924+00:00 | 415 | false | \tbool check(string str)\n\t{\n\t\tint x = 0;\n\t\tfor(int i=0;i<str.size();i++)\n\t\t{\n\t\t\tx=x*10+(str[i]-\'0\');\n\t\t}\n\t\tint z = (x&(x-1));\n\t\tif(z==0)return true;\n\t\treturn false;\n\t}\n\tvoid permute(string &str,int index,bool &ans)\n\t{\n\t\tif(index==str.size())\n\t\t{\n\t\t\tif(str[0]!=\'0\' && check(str))ans = true;\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=index;i<str.size();i++)\n\t\t{\n\t\t\tswap(str[i],str[index]);\n\t\t\tpermute(str,index+1,ans);\n\t\t\tswap(str[i],str[index]);\n\t\t}\n\t}\n\tclass Solution {\n\tpublic:\n\t\tbool reorderedPowerOf2(int n) \n\t\t{\n\t\t\tbool ans = false;\n\t\t\tstring str = to_string(n);\n\t\t\tpermute(str,0,ans);\n\t\t\treturn ans;\n\t\t}\n\t}; | 4 | 0 | ['Backtracking', 'Bit Manipulation', 'Recursion', 'C'] | 1 |
reordered-power-of-2 | C++ Cool & Super Short, 100% faster 0ms | c-cool-super-short-100-faster-0ms-by-deb-pjv1 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) \n {\n static const set<string> pows {"1", "2", "4", "8", "16", "23", "46", "128", "256 | debbiealter | NORMAL | 2021-03-21T08:28:01.680819+00:00 | 2021-03-21T08:31:20.330602+00:00 | 210 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) \n {\n static const set<string> pows {"1", "2", "4", "8", "16", "23", "46", "128", "256", "125", "0124", "0248", "0469", "1289", "13468", "23678", "35566", "011237", "122446", "224588", "0145678", "0122579", "0134449", "0368888", "11266777", "23334455", "01466788", "112234778", "234455668", "012356789", "0112344778"};\n \n string str = to_string(N);\n sort(str.begin(), str.end());\n \n return pows.find(str) != pows.end();\n }\n};\n``` | 4 | 2 | ['C'] | 3 |
reordered-power-of-2 | A Java solution which easy understand | a-java-solution-which-easy-understand-by-w705 | \nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int ans=1;ans<=Math.pow(10,9);ans*=2)\n if(equal(N,ans))\n | rosand | NORMAL | 2018-07-15T06:38:13.166075+00:00 | 2018-07-15T06:38:13.166075+00:00 | 408 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int N) {\n for(int ans=1;ans<=Math.pow(10,9);ans*=2)\n if(equal(N,ans))\n return true;\n return false;\n }\n public boolean equal(int num1,int num2){\n char[] str1 = Integer.toString(num1).toCharArray(),str2 = Integer.toString(num2).toCharArray();\n int[] nums = new int[10];\n for(int i=0;i<str1.length;i++) nums[str1[i] - \'0\']--;\n for(int i=0;i<str2.length;i++) nums[str2[i] - \'0\']++;\n for(int i:nums)\n if(i!=0) return false;\n return true;\n }\n}\n``` | 4 | 0 | [] | 1 |
reordered-power-of-2 | Easy C++ code with explanation || BEATS 100% solutions. | easy-c-code-with-explanation-beats-100-s-57bi | Intuition\nThe problem requires checking if the digits of a number n can be rearranged to form a power of 2. The key insight is that two numbers have the same d | Ajay1112 | NORMAL | 2024-10-09T17:13:45.082647+00:00 | 2024-10-09T17:13:45.082769+00:00 | 216 | false | # Intuition\nThe problem requires checking if the digits of a number n can be rearranged to form a power of 2. The key insight is that two numbers have the same digit arrangement if their sorted digit strings are identical.\n\n# Approach\nConvert n to a string and sort its digits.\n\nPrecompute sorted powers of 2.\n\nGenerate powers of 2 from 2^0 to 2^30.\nFor each power of 2, convert it to a string, sort its digits, and store the result.\nCheck for a match:\n\nCompare the sorted digits of n with each sorted power of 2.\nReturn true if a match is found; otherwise, return false.\n\n# Complexity\n- Time complexity:\nThe conversion and sorting of n takes O(logn) due to the string conversion for the worst case.\n\n- Space complexity:\n\n# Code\n```cpp []\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<string>v;\n string p=to_string(n);\n sort(p.begin(),p.end());\n for(int i=0;i<31;i++){\n long long x=(1LL<<i);\n string s=to_string(x);\n sort(s.begin(),s.end());\n v.push_back(s);\n }\n for(auto it:v){\n if(it==p){\n return true;\n }\n }\n return false;\n }\n};\n``` | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-mkmk | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n {\n if(n==1) return | shishirRsiam | NORMAL | 2024-05-15T07:30:57.188787+00:00 | 2024-05-15T07:31:56.790728+00:00 | 196 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n {\n if(n==1) return true;\n\n string target = to_string(n), temp;\n sort(target.begin(), target.end());\n for(int i=1;i<=32;i++)\n {\n long long val = pow(2, i);\n temp = to_string(val);\n sort(temp.begin(), temp.end());\n if(temp == target) return true;\n }\n return false;\n }\n};\n``` | 3 | 0 | ['Hash Table', 'Math', 'Sorting', 'Counting', 'C++'] | 3 |
reordered-power-of-2 | Solution in C++ | solution-in-c-by-ashish_madhup-bvup | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ashish_madhup | NORMAL | 2023-02-26T16:36:47.608458+00:00 | 2023-02-26T16:36:47.608486+00:00 | 306 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> Helper(long n){\n vector<int>num(10);\n while(n)\n {\n num[n%10]++;\n n=n/10;\n }\n return num;\n }\n bool reorderedPowerOf2(int n)\n {\n vector<int>v=Helper(n);\n for(int i=0;i<31;i++){\n if(v==Helper(1<<i)){\n return true;\n }\n }\n return false;\n }\n};\n``` | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | C++ Clear Solution with Explanation - Runtime: 0 ms, faster than 100.00% | c-clear-solution-with-explanation-runtim-78cm | 1.Brute force Approach: Find all possible combinations of numbers that can be formed from the Given Target number\'s digits and for each combination check if i | aviranjan444 | NORMAL | 2022-12-20T05:04:27.874901+00:00 | 2022-12-20T05:04:27.874943+00:00 | 893 | false | 1.**Brute force Approach:** Find all possible combinations of numbers that can be formed from the Given Target number\'s digits and for each combination check if it is a\n power of 2 or not . (Hint : Convert the number to string )\n 2. **Optimised/Efficient Approach:** We can see the constraint for n is *1 <= n <= 10^9* \n* If somehow we can show that , with the given number\'s digits we can form a number which is a power of 2 , then our job is done!\n* First of all , We will keep the count of the frequency of digits of the given number and then we will check if the frequency count matches or not for every power of 2 within the given constraint.\n* Linear Time Complexity Solution \n```\nclass Solution {\npublic:\n vector<int>nfreq;\n vector<int> util(int n) // To find the freqeuncy of digits of a number\n {\n vector<int>digitFreq(10,0); \n \n while(n>0)\n {\n int rem = n%10;\n n = n/10;\n digitFreq[rem]++;\n }\n return digitFreq;\n }\n bool reorderedPowerOf2(int n) {\n \n nfreq = util(n);\n for(int i= 0;i<32;++i)\n {\n if(nfreq == util(1<<i)) // Checking condition \n return true;\n }\n \n return false;\n }\n};\n``` | 3 | 0 | ['Math', 'C', 'Counting'] | 2 |
reordered-power-of-2 | python short and precise answer | python-short-and-precise-answer-by-benon-h8a4 | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n for i in range(32):\n if Counter(str(n))==Counter(str(2**i)):\n | benon | NORMAL | 2022-08-26T19:17:24.614836+00:00 | 2022-08-26T19:17:24.614871+00:00 | 349 | false | ```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n for i in range(32):\n if Counter(str(n))==Counter(str(2**i)):\n return True\n return False\n | 3 | 0 | ['Python', 'Python3'] | 2 |
reordered-power-of-2 | EASY 6 line C++ code|| Beginner friendly || bitwise | easy-6-line-c-code-beginner-friendly-bit-n1w6 | class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort(s.begin(),s.end());\n do{\n if( s[0 | nematanya | NORMAL | 2022-08-26T14:40:15.970130+00:00 | 2022-08-26T14:43:13.934717+00:00 | 176 | false | class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort(s.begin(),s.end());\n do{\n if( s[0]==\'0\') continue;\n int k=stoi(s);\n if(!(k&k-1)) return true;\n }while(next_permutation(s.begin(),s.end()) );\n return false;\n }\n};\n*Upvote if you liked the solution* | 3 | 0 | [] | 2 |
reordered-power-of-2 | Python || O(log(n)) time, O(1) space || Faster than 100% || Explained and compared | python-ologn-time-o1-space-faster-than-1-ez3f | Approach\nFor all the solutions presented here, the general approach is as follows:\n- Step #1: Identify the digits n is made of.\n- Step #2: Identify the power | RegInt | NORMAL | 2022-08-26T13:29:00.126595+00:00 | 2022-09-06T21:06:11.628757+00:00 | 253 | false | # Approach\nFor all the solutions presented here, the general approach is as follows:\n- **Step #1**: Identify the digits `n` is made of.\n- **Step #2**: Identify the powers of 2 that have the same number of digits as `n`; there are maximum four of them.\n- **Step #3**: Check whether any of the powers of 2 from step **#2** are made of the same digits as identified in step **#1**.\n\n# Solution with the lowest time and space theoretical complexity\n**Description**\nThis solution uses:\n- Integer division by 10 and modulo base 10 to identify the digits making up a given integer value.\n- A `dict` to count the number of occurrences of each digit in a given integer value.\n Such a dict has maximum 10 entries.\n- The comparison between such `dict` instances to check whether two integer values are made up the same digits.\n\n**Complexity**\n- Time: `O(log(n))`\n- Space: `O(1)`\n\n**Code**\nThe code below gave me: `Runtime: 26 ms, faster than 100.00% of Python3 online submissions`\n```\nfrom collections import defaultdict\n\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n # Step #1: Get the digits of `n` and count their occurrences\n # - Time: O(log(n))\n # - Space: O(1), as `digitCounts` has maximum 10 entries\n tmpValue, numDigits, digitCounts = n, 0, defaultdict(int)\n while tmpValue != 0:\n numDigits += 1\n tmpValue, digit = divmod(tmpValue, 10)\n digitCounts[digit] += 1\n\n # Step #2: Identify the smallest power of 2 that has the same number of digits as `n`\n # - Time: O(log(n))\n # - Space: O(1)\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n # Step #3: Out of the powers of 2 that have the same number of digits as `n` (there are maximum four), check if any has the same digits as `n`\n # For this, we count digit occurrences and compare to the ones from step #1\n # - Time: O(log(n))\n # - Space: O(1), as `powerOf2DigitCounts` has maximum 10 entries\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n tmpValue, powerOf2DigitCounts = powerOf2, defaultdict(int)\n while tmpValue != 0:\n numDigits += 1\n tmpValue, digit = divmod(tmpValue, 10)\n powerOf2DigitCounts[digit] += 1\n if powerOf2DigitCounts == digitCounts:\n return True\n powerOf2 <<= 1\n\n return False\n```\n\n# Faster solution: Use string conversion to get the digits\n**Description**\nThis solution uses:\n- String conversion to identify the digits making up a given integer value.\n- A `dict` to count the number of occurrences of each digit in a given integer value.\n Such a dict has maximum 10 entries.\n- The comparison between such `dict` instances to check whether two integer values are made up the same digits.\n\n**Complexity**\n- Time: `O(log(n))`\n- Space: `O(log(n))`\n\n**Code**\nThe code below gave me: `Runtime: 28 ms, faster than 100.00% of Python3 online submissions`\nAgainst LeetCode\'s test suite, this timing does not look as good as the previous solution, **BUT** this is due to LeetCode\'s:\n- Huge variance in running times, even for the exact same code.\n- Test suites often no being comprehensive enough to properly differentiate algorithms.\n\nPlease see the *comparison* section at the end of this post to get a clear picture that this solution is globally faster than the previous one.\n\n```\nfrom collections import defaultdict\n\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n # Step #1: Get the digits of `n` and count their occurrences\n # - Time: O(log(n))\n # - Space: O(log(n)) for the intermediate string\n nStr = str(n)\n numDigits = len(nStr)\n digitCounts = defaultdict(int)\n for digit in nStr:\n digitCounts[digit] += 1\n\n # Step #2: Identify the smallest power of 2 that has the same number of digits as `n`\n # - Time: O(log(n))\n # - Space: O(1)\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n # Step #3: Out of the powers of 2 that have the same number of digits as `n` (there are maximum four), check if any has the same digits as `n`\n # For this, we count digit occurrences and compare to the ones from step #1\n # - Time: O(log(n))\n # - Space: O(log(n)) for the intermediate strings\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n powerOf2Str = str(powerOf2)\n powerOf2DigitCounts = defaultdict(int)\n for digit in powerOf2Str:\n powerOf2DigitCounts[digit] += 1\n if powerOf2DigitCounts == digitCounts:\n return True\n powerOf2 <<= 1\n\n return False\n```\n\n# Fastest solution: Sort the digits rather than counting their occurrences\n**Description**\nThis solution uses:\n- String conversion to identify the digits making up a given integer value.\n- Sorting of the digits.\n- The comparison between such sorted lists to check whether two integer values are made up the same digits.\n\n**Complexity**\n- Time: `O(log(n)*log(log(n)))`\n- Space: `O(log(n))`\n\nAlthough the theoretical time complexity is worse than the previous solutions, in practice this performs noticeable faster, as:\n- We are talking about a relatively small number of digits, so the sorting is actually very fast.\n- The building of a list structure is much faster than the building of a counter dictionary structure.\n\n**Code**\nThe code below gave me: `Runtime: 23 ms, faster than 100.00% of Python3 online submissions`\nPlease see the *comparison* section at the end of this post to get a better sense of how much faster this solution actually is.\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n # Step #1: Get the digits of `n` and sort them\n # - Time: O(log(n)*log(log(n)))\n # - Space: O(log(n))\n nStr = str(n)\n numDigits, sortedDigits = len(nStr), sorted(nStr)\n\n # Step #2: Identify the smallest power of 2 that has the same number of digits as `n`\n # - Time: O(log(n))\n # - Space: O(1)\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n # Step #3: Out of the powers of 2 that have the same number of digits as `n` (there are maximum four), check if any has the same digits as `n`\n # For this, we sort the digits and compare to the ones from step #1\n # - Time: O(log(n)*log(log(n)))\n # - Space: O(log(n))\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n powerOf2Str = str(powerOf2)\n if sorted(powerOf2Str) == sortedDigits:\n return True\n powerOf2 <<= 1\n\n return False\n```\n\n# Timings comparison\nAs mentioned previously, one cannot rely on LeetCode\'s test suites or LeetCode\'s inconsistent running times to get a proper picture of how different algorithms actually compare.\n\nSo, here is some code that compares the 3 solutions presented above, and that anyone can run on their own machine.\nIt generates 1,000,000 test cases with integers of varying sizes; out of these, 332 can be reordered into a power of 2.\n\n**Code**\n```\n# ==================================================================================================\n# Solution with the lowest time and space theoretical complexity\n# ==================================================================================================\n\nfrom collections import defaultdict\nfrom math import ceil, log2\n\nclass Solution_1:\n def reorderedPowerOf2(self, n: int) -> bool:\n tmpValue, numDigits, digitCounts = n, 0, defaultdict(int)\n while tmpValue != 0:\n numDigits += 1\n tmpValue, digit = divmod(tmpValue, 10)\n digitCounts[digit] += 1\n\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n tmpValue, powerOf2DigitCounts = powerOf2, defaultdict(int)\n while tmpValue != 0:\n numDigits += 1\n tmpValue, digit = divmod(tmpValue, 10)\n powerOf2DigitCounts[digit] += 1\n if powerOf2DigitCounts == digitCounts:\n return True\n powerOf2 <<= 1\n\n return False\n\n# ==================================================================================================\n# Faster solution: Use string conversion to get the digits\n# ==================================================================================================\n\nfrom collections import defaultdict\nfrom math import ceil, log2\n\nclass Solution_2:\n def reorderedPowerOf2(self, n: int) -> bool:\n nStr = str(n)\n numDigits = len(nStr)\n digitCounts = defaultdict(int)\n for digit in nStr:\n digitCounts[digit] += 1\n\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n powerOf2Str = str(powerOf2)\n powerOf2DigitCounts = defaultdict(int)\n for digit in powerOf2Str:\n powerOf2DigitCounts[digit] += 1\n if powerOf2DigitCounts == digitCounts:\n return True\n powerOf2 <<= 1\n\n return False\n\n# ==================================================================================================\n# Fastest solution: Sort the digits rather than counting their occurrences\n# ==================================================================================================\n\nfrom math import ceil, log2\n\nclass Solution_3:\n def reorderedPowerOf2(self, n: int) -> bool:\n nStr = str(n)\n numDigits, sortedDigits = len(nStr), sorted(nStr)\n\n minTargetValue = 10 ** (numDigits - 1)\n powerOf2 = 1 << ceil(log2(minTargetValue))\n\n maxTargetValue = 10 * minTargetValue - 1\n while powerOf2 <= maxTargetValue:\n powerOf2Str = str(powerOf2)\n if sorted(powerOf2Str) == sortedDigits:\n return True\n powerOf2 <<= 1\n\n return False\n\n# ==================================================================================================\n# Testing\n# ==================================================================================================\n\nfrom time import perf_counter\n\npowersOf2sortedDigits = frozenset(tuple(sorted(str(powerOf2))) for powerOf2 in (2 ** i for i in range(31)))\ntestCases = [(n, tuple(sorted(str(n))) in powersOf2sortedDigits) for n in (137 * i for i in range(1, 1000001))]\nprint(f"{len(testCases)} test cases out of which {sum(1 for _, expected in testCases if expected is True)} return `True`")\n\nfor Solution in [Solution_1, Solution_2, Solution_3]:\n print(f"*** {Solution.__name__} ***")\n startPerfCounter = perf_counter()\n for n, expected in testCases:\n actual = Solution().reorderedPowerOf2(n)\n assert actual == expected, f"ERROR for arg {n}:\\n- Expected: {expected}\\n- Got: {actual}"\n else:\n endPerfCounter = perf_counter()\n print(f"Completed in {(endPerfCounter - startPerfCounter)}s")\n```\n\n**Results**\nRunning this code on my laptop, I got:\n```\n1000000 test cases out of which 332 return `True`\n*** Solution_1 ***\nCompleted in 10.228865999999925s\n*** Solution_2 ***\nCompleted in 7.209750700000313s\n*** Solution_3 ***\nCompleted in 3.2113036999999167s\n``` | 3 | 0 | ['Python', 'Python3'] | 0 |
reordered-power-of-2 | C++ || 10 4bit counters packet into 64bit integer || fast (0ms) | c-10-4bit-counters-packet-into-64bit-int-sgq7 | Please upvote if you like the solution, it motivates me to post more of them\n\nSolution 1: 10 4bit counters packet into a 64bit integer\n\nThis solution is bas | heder | NORMAL | 2022-08-26T08:44:39.188497+00:00 | 2022-08-26T18:04:20.636006+00:00 | 163 | false | **Please upvote if you like the solution, it motivates me to post more of them**\n\n**Solution 1: 10 4bit counters packet into a 64bit integer**\n\nThis solution is basically do a frequency count. Since any digit (0 to 9) is for sure less frequent than 16 in a 32bit integer we can use 4 bits to count the frequency the digitis. With that we can pack 10 4bit counters easily into a 64bit integer. The solution has to functions:\n\nWe just need to compare the signature of ```n``` with the signature of all powers of 2.\n\n```\n bool reorderedPowerOf2(int n) {\n const uint64_t sig_n = signatur(n);\n // Compare to all powers of 2.\n for (int i = 0; i < 32; ++i) {\n if (sig_n == signatur(1 << i)) return true;\n }\n return false;\n }\n```\n\nThe more interesting part is to compute the singatures:\n\n```\n // We use 4 bits to count each digit.\n static uint64_t signatur(uint32_t n) {\n uint64_t sig = 0;\n while (n) {\n sig += 1UL << ((n % 10) * 4);\n n /= 10;\n }\n return sig;\n }\n```\n\nAlternative to an ```uint64_t``` signature we could have used an ```array<char, 10>``` (or a similar structure) or just use a ```string``` and just sort the digits.\n\nAs always feedback is welcome. | 3 | 0 | ['Bit Manipulation', 'C'] | 0 |
reordered-power-of-2 | [JAVA] Simplest solution so far | NO bitwise | java-simplest-solution-so-far-no-bitwise-tlqn | \npublic boolean reorderedPowerOf2(int n) {\n char[] num = String.valueOf(n).toCharArray();\n Arrays.sort(num);\n for(int i=0;i<30;i++){\n | L_K_G | NORMAL | 2022-08-26T08:21:04.665521+00:00 | 2022-08-26T08:21:04.665563+00:00 | 260 | false | ```\npublic boolean reorderedPowerOf2(int n) {\n char[] num = String.valueOf(n).toCharArray();\n Arrays.sort(num);\n for(int i=0;i<30;i++){\n int intCur = (int)Math.pow(2,i);\n char[] charCur = String.valueOf(intCur).toCharArray();\n Arrays.sort(charCur);\n if(Arrays.equals(num,charCur))\n return true;\n }\n return false;\n }\n``` | 3 | 0 | ['Sorting', 'Java'] | 0 |
reordered-power-of-2 | Daily Challenge | C++ | 100% FASTER | EASY | HASHING | daily-challenge-c-100-faster-easy-hashin-qvx6 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n int arr[10];\n memset(arr,0,sizeof(arr));\n \n int x =n;\n | hritik_01478 | NORMAL | 2022-08-26T06:21:18.778314+00:00 | 2022-08-26T06:21:18.778347+00:00 | 110 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n int arr[10];\n memset(arr,0,sizeof(arr));\n \n int x =n;\n for(;x>0;){\n int rem = x%10;\n arr[rem]++;\n x = x/10;\n }\n for(int i=0; i<31; i++){\n int check[10];\n memset(check,0,sizeof(check));\n int y = pow(2,i);\n while(y>0){\n int rem = y%10;\n check[rem]++;\n y = y/10;\n }\n bool flag = true;\n for(int j=0; j<10; j++){\n if(arr[j]!=check[j]){\n flag = false;\n break;\n }\n }\n if(flag){\n return true;\n }\n }\n return false;\n }\n};\n``` | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | C++||Easy understand|| | ceasy-understand-by-mickyt711ss-idqu | core concept\nWe can use 2147483648%numto determinenum is power of 2 or not.\nI hope this concept can help you~~~\nif you think this is useful, please upvoted i | mickyt711ss | NORMAL | 2022-08-26T05:49:12.410025+00:00 | 2022-08-26T05:52:10.268090+00:00 | 40 | false | # core concept\nWe can use `2147483648%num`to determine` num` is power of 2 or not.\nI hope this concept can help you~~~\nif you think this is useful, please upvoted it to let more people see this article.\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s=to_string(n);\n sort(s.begin(),s.end());\n do{\n if(2147483648%stoi(s)==0&&s[0]!=\'0\') return 1;\n }while(next_permutation(s.begin(), s.end()));\n return 0;\n }\n};\n``` | 3 | 0 | [] | 0 |
reordered-power-of-2 | Simple Cpp Solution | simple-cpp-solution-by-sanket_jadhav-a3c2 | ```\nclass Solution {\npublic:\n vector func(int n){\n vectorans(10);\n \n while(n){\n ans[n%10]++;\n n/=10;\n | Sanket_Jadhav | NORMAL | 2022-08-26T03:49:17.802501+00:00 | 2022-08-26T03:49:17.802539+00:00 | 47 | false | ```\nclass Solution {\npublic:\n vector<int> func(int n){\n vector<int>ans(10);\n \n while(n){\n ans[n%10]++;\n n/=10;\n }\n \n return ans;\n } \n \n bool reorderedPowerOf2(int n) {\n \n if((n&(n-1))==0)return true;\n \n vector<int>ans=func(n);\n \n for(int i=1;i<31;i++){\n vector<int>v=func(1<<i);\n if(v==ans)return true;\n }\n \n return false;\n }\n}; | 3 | 0 | ['C++'] | 0 |
reordered-power-of-2 | c++ simple solution | c-simple-solution-by-pajju_0330-q4gu | Convert our given number to string (to_string())\n2. Sort it (sort())\n3. Compare it will all sorted string forms of 2 power numbers upto 30 ( 2^31 > 10^9)\n4 | Pajju_0330 | NORMAL | 2022-08-26T03:28:12.883376+00:00 | 2022-08-26T03:28:12.883419+00:00 | 77 | false | 1. Convert our given number to string (`to_string()`)\n2. Sort it (`sort()`)\n3. Compare it will all sorted string forms of 2 power numbers upto 30 ( 2^31 > 10^9)\n4. If equals to anyone return `true`\n5. else if no-match found return `false`\n\n**PLEASE UPVOTE IF YOU LIKED THIS \uD83D\uDE09\uD83D\uDE4C**\n\n\n\n\n\n```\nbool reorderedPowerOf2(int n) {\n\tstring s = sortedString(n);\n\tfor(int i = 0; i < 30; ++i){\n\t\tif(s == sortedString(1<<i)) return true;\n\t}\n\treturn false;\n}\nstring sortedString(int n){\n\tstring s = to_string(n);\n\tsort(s.begin(),s.end());\n\treturn s;\n}\n``` | 3 | 0 | ['C', 'Sorting'] | 0 |
reordered-power-of-2 | SIMPLE C++ SOLUTION | simple-c-solution-by-lokeshthaduri1-1d7d | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n if(n == 1) return true;\n unordered_map<int, int> map;\n \n strin | lokeshthaduri1 | NORMAL | 2022-08-26T02:29:08.284004+00:00 | 2022-08-26T02:29:08.284035+00:00 | 798 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n if(n == 1) return true;\n unordered_map<int, int> map;\n \n string temp = to_string(n);\n for(int i = 0; i < temp.size(); i++){\n map[int(temp[i])-48]++;\n } \n \n int digits = temp.size();\n return helper(map, 1, n, digits);\n }\n \n bool helper(unordered_map<int, int> map, long k, int s, int digits){\n if(k > pow(10, digits) - 1) return false;\n if(k == s) return true;\n \n unordered_map<int, int> copy = map;\n \n string temp = to_string(k);\n for(int i = 0; i < temp.size(); i++){\n copy[int(temp[i])-48]--;\n }\n \n for(auto &it: copy){\n if(it.second != 0) return helper(map, k*2, s, digits);\n }\n \n return true;\n }\n};\n``` | 3 | 1 | ['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
reordered-power-of-2 | Go | Golang Solution | go-golang-solution-by-d901203-ut6m | \nfunc reorderedPowerOf2(n int) bool {\n\tstr := strconv.Itoa(n)\n\tstrByte := []byte(str)\n\tsort.Slice(strByte, func(i, j int) bool { return strByte[i] < strB | d901203 | NORMAL | 2022-08-26T01:34:00.529877+00:00 | 2022-08-26T01:49:42.406387+00:00 | 129 | false | ```\nfunc reorderedPowerOf2(n int) bool {\n\tstr := strconv.Itoa(n)\n\tstrByte := []byte(str)\n\tsort.Slice(strByte, func(i, j int) bool { return strByte[i] < strByte[j] })\n\tfor i := 0; i < 31; i++ {\n\t\ttmp := strconv.Itoa(1 << i)\n\t\ttmpByte := []byte(tmp)\n\t\tsort.Slice(tmpByte, func(i, j int) bool { return tmpByte[i] < tmpByte[j] })\n\t\tif string(strByte) == string(tmpByte) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n```\n\nuse slice as counter (can\'t use == to compare two slice)\n```\nfunc reorderedPowerOf2(n int) bool {\n\tcount := func(n int) []int {\n\t\tresult := make([]int, 10)\n\t\tfor n > 0 {\n\t\t\tresult[n%10]++\n\t\t\tn /= 10\n\t\t}\n\t\treturn result\n\t}\n\tcompare := func(s1, s2 []int) bool {\n\t\tfor i := 0; i < 10; i++ {\n\t\t\tif s1[i] != s2[i] {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tnCnt := count(n)\n\tfor i := 0; i < 31; i++ {\n\t\tif compare(nCnt, count(1<<i)) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n```\n\nuse array as counter (can use == to compare two array)\n```\nfunc reorderedPowerOf2(n int) bool {\n\tcount := func(n int) [10]int {\n\t\tvar result [10]int\n\t\tfor n > 0 {\n\t\t\tresult[n%10]++\n\t\t\tn /= 10\n\t\t}\n\t\treturn result\n\t}\n\tnCnt := count(n)\n\tfor i := 0; i < 31; i++ {\n\t\tif nCnt == count(1<<i) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n``` | 3 | 0 | ['Go'] | 1 |
reordered-power-of-2 | [Java] [1ms][100% Faster] Compare Frequency with all powers of 2 | java-1ms100-faster-compare-frequency-wit-l3vs | \n\n\n\nclass Solution {\n\n public boolean reorderedPowerOf2(int n) {\n final int[] frequency = new int[10];\n int digitCount = 0;\n\n | java-lang-goutam | NORMAL | 2022-08-26T00:49:08.736145+00:00 | 2022-08-26T00:56:34.826882+00:00 | 267 | false | \n\n\n```\nclass Solution {\n\n public boolean reorderedPowerOf2(int n) {\n final int[] frequency = new int[10];\n int digitCount = 0;\n\n while (n > 0) {\n frequency[n % 10]++;\n n /= 10;\n digitCount++;\n }\n\n int currP = 1;\n\n while (currP > 0) {\n final int[] currFreq = new int[10];\n int currDigitCount = 0;\n int currN = currP;\n\n while (currN > 0) {\n currFreq[currN % 10]++;\n currN /= 10;\n currDigitCount++;\n }\n\n if (currDigitCount > digitCount) return false;\n if (currDigitCount == digitCount && Arrays.equals(currFreq, frequency)) return true;\n\n currP <<= 1;\n }\n\n return false;\n }\n}\n```\n\n**Please Upvote :)** | 3 | 2 | ['Bit Manipulation', 'Java'] | 0 |
reordered-power-of-2 | Track with Hashmap | Easy & Simple Solution | track-with-hashmap-easy-simple-solution-v35ha | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<int> powers;\n for(int i=1;i<=1e9;i*=2){\n powers.push_back(i | sunny_38 | NORMAL | 2022-03-06T05:59:50.545011+00:00 | 2022-03-06T05:59:50.545041+00:00 | 56 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<int> powers;\n for(int i=1;i<=1e9;i*=2){\n powers.push_back(i);\n }\n \n map<int,int> demand;\n while(n>0){\n demand[n%10]++;\n n/=10;\n }\n \n for(auto& num:powers){\n map<int,int> curr;\n while(num>0){\n curr[num%10]++;\n num/=10;\n }\n \n if(curr==demand){\n return true;\n }\n }\n \n return false;\n }\n};\n``` | 3 | 0 | [] | 0 |
reordered-power-of-2 | Easy to understand python solution. | easy-to-understand-python-solution-by-19-llq1 | ```\n\t\tl = sorted(list(str(n)))\n for i in range(30):\n a = 2**i\n b = sorted(list(str(a)))\n if l == b:\n | 1903480100017_A | NORMAL | 2021-12-07T19:07:18.552346+00:00 | 2021-12-07T19:07:18.552390+00:00 | 306 | false | ```\n\t\tl = sorted(list(str(n)))\n for i in range(30):\n a = 2**i\n b = sorted(list(str(a)))\n if l == b:\n return True\n | 3 | 0 | ['Python', 'Python3'] | 0 |
reordered-power-of-2 | Java || 1ms(97.25% faster) | java-1ms9725-faster-by-viking05-zc44 | Explanation\n1) Store the count of digits of given n in an array.\n2) Store the count of digits of every power of 2 from 1 to 30.\n3) If the count of digits in | viking05 | NORMAL | 2021-10-28T12:38:05.254965+00:00 | 2021-10-28T12:38:05.254991+00:00 | 107 | false | **Explanation**\n1) Store the count of digits of given n in an array.\n2) Store the count of digits of every power of 2 from 1 to 30.\n3) If the count of digits in any of the power of 2 matches with the count of digits of given n, then return true. \n4) If a match is not found after all iterations, that means the given number cannot be arranged in the form of a power of 2. Hence, return false.\n```\nclass Solution \n{\n public boolean reorderedPowerOf2(int n) \n {\n int[] cnt = new int[10];\n int num = n;\n while(num != 0)\n {\n cnt[num % 10]++;\n num /= 10;\n }\n \n int two = 1;\n int pow = 1;\n while(pow <= 30)\n {\n int cur[] = new int[10];\n num = two;\n while(num != 0)\n {\n cur[num % 10]++;\n num /= 10;\n }\n \n boolean powOfTwo = true;\n for(int i=0; i<10; i++)\n {\n if(cnt[i] != cur[i])\n {\n powOfTwo = false;\n break;\n }\n }\n if(powOfTwo)\n return true;\n two *= 2;\n pow++;\n }\n return false;\n } \n}\n``` | 3 | 0 | [] | 1 |
reordered-power-of-2 | Java Simple and easy solution,1 ms, faster than 96.64%, T O(1), S O(1) clean code with comments. | java-simple-and-easy-solution1-ms-faster-u9s2 | PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\nclass Solution {\n //store all the power of 2 digits,\n //only do this operation 1 time\n static PowerOf | satyaDcoder | NORMAL | 2021-03-22T01:36:51.446487+00:00 | 2021-03-22T01:36:51.446529+00:00 | 342 | false | **PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n```\nclass Solution {\n //store all the power of 2 digits,\n //only do this operation 1 time\n static PowerOfTwo powerOfTwo = new PowerOfTwo();\n \n public boolean reorderedPowerOf2(int N) {\n String numDigit = String.valueOf(N);\n \n /*\n Approach\n 1. calculate one time only, power of 2\n and store \n 2. for given number, if its digit is anagram of any\n stored power of 2 digits, return true otherwise false\n 3. Time O(1), Space O(1)\n */\n \n \n for(String power : powerOfTwo.digits){\n if(isAnagrams(power, numDigit)){\n return true;\n }\n }\n \n return false;\n }\n \n \n private boolean isAnagrams(String str1, String str2){\n if(str1.length() != str2.length()) return false;\n \n int[] counts = new int[10];\n \n for(char digit : str1.toCharArray()){\n counts[digit - \'0\']++;\n }\n \n for(char digit : str2.toCharArray()){\n counts[digit - \'0\']--;\n }\n \n for(int count : counts){\n if(count != 0) return false;\n }\n\n return true;\n }\n}\n\nclass PowerOfTwo{\n String[] digits;\n \n public PowerOfTwo(){\n digits = new String[30];\n \n for(int i = 0; i < digits.length; i++){\n digits[i] = String.valueOf((1 << i));\n }\n }\n \n}\n``` | 3 | 0 | ['Java'] | 0 |
reordered-power-of-2 | [C++/Python] Direct simulation & Indirect checking all possibilities of Power of 2 | cpython-direct-simulation-indirect-check-zam5 | Idea1: Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgori | codedayday | NORMAL | 2021-03-21T17:14:28.514980+00:00 | 2021-03-21T17:23:16.091217+00:00 | 150 | false | Idea1: Direct simulation of Permutations [1]\nIntuition\n\nFor each permutation of the digits of N, let\'s check if that permutation is a power of 2.\n\nAlgorithm\n\nThis approach has two steps: how will we generate the permutations of the digits, and how will we check that the permutation represents a power of 2?\n\nTo generate permutations of the digits, we place any digit into the first position (start = 0), then any of the remaining digits into the second position (start = 1), and so on. In Python, we can use the builtin function itertools.permutations.\n\nTo check whether a permutation represents a power of 2, we check that there is no leading zero, and divide out all factors of 2. If the result is 1 (that is, it contained no other factors besides 2), then it was a power of 2. In Python, we can use the check bin(N).count(\'1\') == 1.\n\n```\nTime Complexity: O((logN)!\u2217logN). Note that logN is the number of digits in the binary representation of N. For each of (logN)! permutations of the digits of N, we need to check that it is a power of 2 in O(logN) time.\n\nSpace Complexity: O(logN), the space used by A (or cand in Python).\n```\n\nApproach 1: C++\n\n\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n vector<int> digits;\n while(N>0){\n digits.push_back(N%10);\n N /= 10;\n }\n \n sort(digits.begin(), digits.end()); \n do{\n if( digits[0] != 0 && __builtin_popcount(digit2num(digits)) == 1)\n return true;\n }while(next_permutation(digits.begin(), digits.end()));\n return false;\n }\n \nprivate:\n int digit2num(vector<int>& digits){\n int ans = 0;\n for(auto digit: digits)\n ans = ans * 10 + digit;\n return ans;\n }\n};\n```\n\nApproach 2: Python\n```\nclass Solution:\n def reorderedPowerOf2(self, N: int) -> bool:\n for cand in itertools.permutations(str(N)):\n if cand[0]!=\'0\' and bin(int("".join(cand))).count(\'1\') ==1:\n return True\n return False\n #return any( cand[0]!=\'0\' and bin(int("".join(cand))).count(\'1\') ==1\n # for cand in itertools.permutations(str(N)))\n #for cand in iterationtools.permutation(str(N)))\n```\n\n\n\nIdea2: Counting\nIntuition and Algorithm\n\nWe can check whether two numbers have the same digits by comparing the count of their digits. For example, 338 and 833 have the same digits because they both have exactly two 3\'s and one 8.\nSince NN could only be a power of 2 with 9 digits or less (namely, 2^0, 2^1, 2^31), we can just check whether NN has the same digits as any of these possibilities.\n\nComplexity Analysis\n\nTime Complexity: O( (logN)^2). There are logN different candidate powers of 2, and each comparison has O(logN) time complexity.\nSpace Complexity: O(logN).\n\n\n```\nclass Solution(object):\n def reorderedPowerOf2(self, N):\n count = collections.Counter(str(N))\n return any(count == collections.Counter(str(1 << b))\n for b in xrange(31))\n```\n\nReference:\n[1] https://leetcode.com/problems/reordered-power-of-2/solution/\n[2] itertools.permutations:\nIllustration:\n\nN=128\n\n>>> for cand in itertools.permutations(str(N)):print(cand)\n...\n(\'1\', \'2\', \'8\')\n(\'1\', \'8\', \'2\')\n(\'2\', \'1\', \'8\')\n(\'2\', \'8\', \'1\')\n(\'8\', \'1\', \'2\')\n(\'8\', \'2\', \'1\')\n>>> for cand in itertools.permutations([1,2,8]):print(cand)\n...\n(1, 2, 8)\n(1, 8, 2)\n(2, 1, 8)\n(2, 8, 1)\n(8, 1, 2)\n(8, 2, 1) | 3 | 0 | ['Bit Manipulation', 'C', 'Python'] | 1 |
reordered-power-of-2 | Reordered Power of 2 | Beats 100% | C++ | reordered-power-of-2-beats-100-c-by-shub-pxtt | The steps for solution to this problem are :\n Store all the powers of 2 in a vector\n Compare each numbner in vector with the given number to check if both hav | Shubh4nk | NORMAL | 2021-03-21T09:42:53.320691+00:00 | 2021-03-21T09:45:09.121577+00:00 | 147 | false | The steps for solution to this problem are :\n* Store all the powers of 2 in a vector\n* Compare each numbner in vector with the given number to check if both have same digits .\n* If both have same digits , return true\n* else return false .\nPls upvote if u feel it is correct and suggest if it can be improved .\n\n\n```\nclass Solution {\npublic:\n int comp(int a,int b)\n {\n bool A[10]={0},B[10]={0};\n int lena=0,lenb=0;\n while(a>0 || b>0)\n {\n if(a>0)\n {\n A[a%10]=1;\n a/=10;\n lena++;\n }\n if(b>0)\n {\n B[b%10]=1;\n b/=10;\n lenb++;\n }\n }\n \n if(lena!=lenb)\n return false;\n \n for(int i=0 ;i<10 ;i++)\n if(A[i]!=B[i])\n return false;\n return true;\n }\n \n bool reorderedPowerOf2(int N) {\n int k=1;\n vector<int> v;\n for(int i=0 ;i<30 ;i++)\n {\n v.push_back(k);\n k*=2;\n }\n \n for(int i=0 ;i<=30 ;i++)\n {\n if(comp(N,v[i]))\n return true;\n }\n return false;\n }\n};\n``` | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | Rust counting solution | rust-counting-solution-by-sugyan-gff1 | rust\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n let digit_counts = |n: i32| -> [usize; 10] {\n let mut n = n;\n | sugyan | NORMAL | 2021-03-21T08:12:26.229592+00:00 | 2021-03-21T08:12:26.229623+00:00 | 90 | false | ```rust\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n let digit_counts = |n: i32| -> [usize; 10] {\n let mut n = n;\n let mut d = [0; 10];\n while n > 0 {\n d[(n % 10) as usize] += 1;\n n /= 10;\n }\n d\n };\n let counts = digit_counts(n);\n (0..31).any(|i| digit_counts(1 << i) == counts)\n }\n}\n``` | 3 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | Python | python-by-gsan-r9sb | As N is bounded by 10^9 we need to check at most the 30-th power of 2. For each power of 2 we count the occurrence of every digit and store it in an array of si | gsan | NORMAL | 2021-03-21T07:16:26.965222+00:00 | 2021-03-21T07:16:26.965259+00:00 | 129 | false | As `N` is bounded by 10^9 we need to check at most the 30-th power of 2. For each power of 2 we count the occurrence of every digit and store it in an array of size 10 (from 0,...,9). If for any power of 2 the count matches that of `N` we return True. Else return False.\n\nTime: `O(1)`\nSpace: `O(1)`\n\n```python\nclass Solution:\n def reorderedPowerOf2(self, N):\n def is_equal(c1, c2):\n return sum(abs(x-y) for x,y in zip(c1,c2))==0\n \n \n def count(n):\n c = [0]*10\n while n:\n c[n % 10] += 1\n n //= 10\n return c\n \n \n c1 = count(N)\n for i in range(31):\n c2 = count(2**i)\n if is_equal(c1, c2):\n return True\n return False\n``` | 3 | 0 | [] | 0 |
reordered-power-of-2 | Easy + Short + Understandable code in C++ || | easy-short-understandable-code-in-c-by-d-vpq6 | using compare function for removing 0 as first digit\n\nstatic bool com(char a,char b){\n return a>b;\n }\n bool reorderedPowerOf2(int N) {\n | darsh19 | NORMAL | 2020-12-21T18:16:30.408095+00:00 | 2020-12-21T18:16:30.408132+00:00 | 263 | false | #using compare function for removing 0 as first digit\n```\nstatic bool com(char a,char b){\n return a>b;\n }\n bool reorderedPowerOf2(int N) {\n string s= to_string(N);\n int n=s.size();\n int k=1;\n string p;\n sort(s.begin(),s.end(),com);\n while(n>=p.size())\n {\n p=to_string(k);\n sort(p.begin(),p.end(),com); //sort every power of twofor checking \n if(s==p)\n return 1;\n k=k<<1; //using for finding next power of two\n }\n return 0;\n \n }\n``` | 3 | 0 | ['C'] | 0 |
reordered-power-of-2 | Another 0ms C++ solution, No special data structure. | another-0ms-c-solution-no-special-data-s-0xfx | \n int myPow(int a) { // returns 10^a;\n if(!a) return 1;\n\n int res=1;\n while(a--)\n\t\t\t\tres *= 10;\n\n retur | mbanik | NORMAL | 2018-07-16T18:21:11.940584+00:00 | 2018-07-16T18:21:11.940584+00:00 | 314 | false | ```\n int myPow(int a) { // returns 10^a;\n if(!a) return 1;\n\n int res=1;\n while(a--)\n\t\t\t\tres *= 10;\n\n return res;\n }\n\n int counter(int N, int& c1 ) {\n int res = 0;\n\n for (; N; N /= 10) {res += myPow(N%10); c1++;}\n\n return res;\n }\n\n\n bool reorderedPowerOf2(int N) {\n if(N<10) {\n if(N==1 || N==2 || N==4 || N==8) return true;\n return false;\n }\n \n int c, cc=0;\n c = counter(N, cc);\n\n for (int i = 2*cc, k; i < 3*cc+3; i++)\n if (counter(1 << i, k) == c) return true;\n\n return false;\n } \n\t\t``` | 3 | 1 | [] | 0 |
reordered-power-of-2 | [Python] easy to understand with explanation | python-easy-to-understand-with-explanati-h6tp | Since the leading digit is not zero, the reordered number shares the same number of digits with original one.\nThe search base can be greatly reduced.\nReturn t | rosaniline | NORMAL | 2018-07-15T04:53:57.976760+00:00 | 2018-07-15T04:53:57.976760+00:00 | 542 | false | Since the leading digit is not zero, the reordered number shares the same number of digits with original one.\nThe search base can be greatly reduced.\nReturn true if `Counter(N) == Counter(power of 2) and NumberOfDigits(N) == NumberOfDigits(power of 2)`\n\n```python\n def reorderedPowerOf2(self, N):\n from collections import Counter\n\n digits_of_n = len(str(N))\n counter = Counter(str(N))\n power = 1\n\n while True:\n digits_of_power = len(str(power))\n\n if digits_of_power > digits_of_n:\n break\n \n if digits_of_power == digits_of_n and Counter(str(power)) == counter:\n return True\n\n power = power*2\n\n return False\n``` | 3 | 0 | [] | 2 |
reordered-power-of-2 | Rust | O(1) | 1ms | rust-o1-1ms-by-user7454af-7lcz | Intuition\nCheck if number has digits matching any power of two.\n\n# Approach\nTake digits of every power of two into an array, sort them and store them in a s | user7454af | NORMAL | 2024-06-29T22:40:20.126620+00:00 | 2024-06-29T22:40:20.126656+00:00 | 23 | false | # Intuition\nCheck if number has digits matching any power of two.\n\n# Approach\nTake digits of every power of two into an array, sort them and store them in a set. Then see if the digits array of given number is present in the set.\n\n# Complexity\n- Time complexity: $$O(1)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nuse std::collections::*;\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n let mut set = HashSet::new();\n let num_2_set = |mut n: i32| -> Vec<i32> {\n let mut v = Vec::with_capacity(10);\n while n > 0 {\n v.push(n%10);\n n /= 10;\n }\n v.sort();\n v\n };\n for i in 0..31 {\n set.insert(num_2_set(1 << i));\n }\n set.contains(&(num_2_set(n)))\n }\n}\n``` | 2 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | Solution | solution-by-deleted_user-h2av | C++ []\nclass Solution {\n public:\n bool reorderedPowerOf2(int N) {\n int count = counter(N);\n\n for (int i = 0; i < 30; ++i)\n if (counter(1 << i | deleted_user | NORMAL | 2023-05-08T06:22:02.064193+00:00 | 2023-05-08T07:30:02.150498+00:00 | 513 | false | ```C++ []\nclass Solution {\n public:\n bool reorderedPowerOf2(int N) {\n int count = counter(N);\n\n for (int i = 0; i < 30; ++i)\n if (counter(1 << i) == count)\n return true;\n\n return false;\n }\n private:\n int counter(int n) {\n int count = 0;\n\n for (; n > 0; n /= 10)\n count += pow(10, n % 10);\n\n return count;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n\n t = sorted(str(n))\n i = 0\n while len(str(2**i))<=len(str(n)):\n if t==sorted(str(2**i)):\n return True\n i+=1\n return False\n```\n\n```Java []\nclass Solution {\n static byte[][] ocurr;\n public boolean reorderedPowerOf2(int n) {\n if (n == 1) return true;\n if (ocurr == null) {\n ocurr = fillOccurencesForEachPowerOf2();\n }\n byte[] freq = countFreqs(n);\n for (byte[] oc : ocurr) {\n if (areSame(oc, freq)) {\n return true;\n }\n }\n return false;\n }\n private byte[][] fillOccurencesForEachPowerOf2() {\n byte[][] res = new byte[30][10];\n for (int i = 0; i < res.length; i++) {\n int pow = (int) Math.pow(2, i);\n res[i] = countFreqs(pow);\n }\n return res;\n }\n private byte[] countFreqs(int pow) {\n byte[] freq = new byte[10];\n while (pow > 0) {\n int digit = pow % 10;\n freq[digit]++;\n pow /= 10;\n }\n return freq;\n }\n private boolean areSame(byte[] oc, byte[] freq) {\n for (int i = 0; i < oc.length; i++) {\n if (oc[i] != freq[i]) return false;\n }\n return true;\n }\n}\n```\n | 2 | 0 | ['C++', 'Java', 'Python3'] | 0 |
reordered-power-of-2 | C++ || short and 100% fast | c-short-and-100-fast-by-moj_leetcode-m4s9 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n)\n {\n string nn = to_string(n);\n \n sort(nn.begin(), nn.end());\n | moj_leetcode | NORMAL | 2023-03-26T12:32:13.275146+00:00 | 2023-03-26T12:32:13.275185+00:00 | 295 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n)\n {\n string nn = to_string(n);\n \n sort(nn.begin(), nn.end());\n \n for (int i = 0; i < 32; i++)\n {\n string pp = to_string(1 << i);\n \n sort(pp.begin(), pp.end());\n \n if (pp == nn)\n return true;\n }\n \n return false;\n }\n};\n``` | 2 | 0 | [] | 0 |
reordered-power-of-2 | Js EASIEST to follow (One glance you will get it!). FASTEST. | js-easiest-to-follow-one-glance-you-will-lg07 | Have fun :)\n\n# Intuition\nhttps://onlinenumbertools.com/sort-digits\n\n\n# Code\n\nvar reorderedPowerOf2 = function (n) {\n const vals = new Set(["1","2","4" | hanbi58 | NORMAL | 2022-12-26T09:12:20.924558+00:00 | 2022-12-26T09:13:35.868900+00:00 | 179 | false | Have fun :)\n\n# Intuition\nhttps://onlinenumbertools.com/sort-digits\n\n\n# Code\n```\nvar reorderedPowerOf2 = function (n) {\n const vals = new Set(["1","2","4","8","16","23","46","128","256","125","0124","0248","0469","1289","13468","23678","35566","011237","122446","224588","0145678","0122579","0134449","0368888","11266777","23334455","01466788","112234778","234455668","012356789",]);\n return vals.has(("" + n).split("").sort((a, b) => a - b).join(""))\n};\n\n``` | 2 | 0 | ['JavaScript'] | 1 |
reordered-power-of-2 | Java 100% Faster | 1 ms solution | Explained | java-100-faster-1-ms-solution-explained-b2ntc | Approach\nExplanation.\n\nOccur is an 2d array which stores occurrences of all digits of each number (power of 2). \n\nExample: 2^16 = 65536, array with occuren | tbekpro | NORMAL | 2022-11-18T15:32:44.275369+00:00 | 2022-11-18T15:32:44.275405+00:00 | 687 | false | # Approach\nExplanation.\n\n**Occur** is an 2d array which stores occurrences of all digits of each number (power of 2). \n\nExample: 2^16 = 65536, array with occurences of digits for it will be: [0,0,0,1,0,2,2,0,0,0], because we have one occurence of 3, two occurences of 5, and two occurences of 6.\n\n**Occur** is $$static$$ because I fill it only once and use for each test case.\n\nThe names of methods are self explainable.\n\n# Code\n```\nclass Solution {\n\n static byte[][] ocurr;\n\n public boolean reorderedPowerOf2(int n) {\n if (n == 1) return true;\n if (ocurr == null) {\n ocurr = fillOccurencesForEachPowerOf2();\n }\n\n byte[] freq = countFreqs(n);\n for (byte[] oc : ocurr) {\n if (areSame(oc, freq)) {\n return true;\n }\n }\n return false;\n }\n\n private byte[][] fillOccurencesForEachPowerOf2() {\n byte[][] res = new byte[30][10];\n for (int i = 0; i < res.length; i++) {\n int pow = (int) Math.pow(2, i);\n res[i] = countFreqs(pow);\n }\n return res;\n }\n\n private byte[] countFreqs(int pow) {\n byte[] freq = new byte[10];\n while (pow > 0) {\n int digit = pow % 10;\n //increment digits frequency for number pow\n freq[digit]++;\n pow /= 10;\n }\n return freq;\n }\n\n private boolean areSame(byte[] oc, byte[] freq) {\n for (int i = 0; i < oc.length; i++) {\n if (oc[i] != freq[i]) return false;\n }\n return true;\n }\n}\n``` | 2 | 0 | ['Java'] | 0 |
reordered-power-of-2 | c++ | easy | short | c-easy-short-by-venomhighs7-f3zx | \n\n# Code\n\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n v | venomhighs7 | NORMAL | 2022-11-06T04:21:31.268815+00:00 | 2022-11-06T04:21:31.268857+00:00 | 204 | false | \n\n# Code\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n vector<string> power;\n for(int i=0;i<=30;i++){\n int p = pow(2,i);\n power.push_back(to_string(p));\n }\n \n for(int i=0;i<=30;i++){\n sort(power[i].begin(),power[i].end());\n }\n \n for(int i=0;i<=30;i++){\n if(power[i] == s ) return true;\n }\n return false;\n }\n};\n``` | 2 | 0 | ['C++'] | 0 |
reordered-power-of-2 | C++ || 100% fast || 0ms | c-100-fast-0ms-by-akshat0610-9w20 | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n{\n string str = to_string(n);\n sort(str.begin(),str.end());\n long long int num;\n in | akshat0610 | NORMAL | 2022-10-29T09:07:35.036341+00:00 | 2022-10-29T09:07:35.036392+00:00 | 981 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) \n{\n string str = to_string(n);\n sort(str.begin(),str.end());\n long long int num;\n int counter=0;\n \n while(true)\n {\n num = pow(2,counter++);\n \n string temp = to_string(num);\n \n \n if(temp.length()>str.length())\n {\n //cout<<"temp="<<temp<<endl;\n break;\n }\n \n sort(temp.begin(),temp.end());\n \n if(str == temp)\n return true;\n \n } \n return false; \n}\n};\n``` | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | Understanding Reordered Power of 2 in 3 Basic Steps | understanding-reordered-power-of-2-in-3-if0cf | I broke it down into 3 core parts:\n1. Identify individual digits of the number\n2. Identify valid permutations of the digits\n3. Test to see if a permutation i | vinniep79 | NORMAL | 2022-09-01T20:38:56.406151+00:00 | 2022-09-01T20:38:56.406185+00:00 | 45 | false | I broke it down into 3 core parts:\n1. Identify individual digits of the number\n2. Identify valid permutations of the digits\n3. Test to see if a permutation is a power of 2.\n\n**Step 1: Identify the Digits**\nIf I as a human see the number 1,024, I\'ll list the digits from left-to-right: 1, 0, 2, 4. But if I want a computer to do it, I\'m better off going from right-to-left: 4, 2, 0, 1. How can we make the computer do this? How can we ask it to tell us, "What\'s in the 1\'s column?"\n\n1. Divide the number by 10: `1024 / 10 = 102`\n2. Multiply by it by 10: `102 * 10 = 1020`\n3. Subtract this result from the original value: `1024 - 1020 = 4`\n\nJust divide the original number by 10 and repeat the process until you run out of digits!\n\n**Step 2: Identify Valid Permutations**\nHow many different ways can we arrange these digits, and what are they? Well, do we actually care? We don\'t really need to *enumerate* the permutations, we just need to *identify* them. That\'s a boolean test. If I ask you, "Is 4210 a permutation of the digits in 1024?" how do you answer that question? If you\'re like me, you just check to see if all digits have been used. \n\nYou can use an integer array of length 10 to count the digits in the input number. For each digit observed in step 1, increment the corresponding index in the array. Using 1024 (or 4210!) as our example, the resulting array should be: `[1, 1, 1, 0, 1, 0, 0, 0, 0, 0]`\n\nIf our input number was `55,963,220`, the array would be: `[1, 0, 2, 1, 0, 2, 1, 0, 0, 1]`\n\nIf two numbers\' arrays are equal, then the digits of one number can be rearranged to make the other!\n\n**Step 3: Test Powers of 2**\nWho remembers their big O times? What grows faster: `O(x^2)`, or `O(2^x)`? The anwer is the latter. `2^x` grows pretty quickly. In fact, `2^30 == 1,073,741,824`, and that\'s greater than a billion. The problem statement says that n will be less than 10 to the 9th, which means we only have 30 dfferent powers of 2 that we\'d need to test. That\'s a pretty small data set to test! Just generate powers of 2, and extract their digits into an array, and compare to the array of digits for our given number. If they match, it means our number can be rearranged to make a power of 2. | 2 | 0 | [] | 1 |
reordered-power-of-2 | Simple Solution using Next Permutation to find the Answer | simple-solution-using-next-permutation-t-j8u1 | \nclass Solution {\npublic:\n vector<int> tovector(int n){\n vector<int> ans;\n while(n!=0){\n ans.push_back(n%10);\n n = | priyanshu2000 | NORMAL | 2022-08-26T18:57:06.299092+00:00 | 2022-08-26T18:57:06.299134+00:00 | 80 | false | ```\nclass Solution {\npublic:\n vector<int> tovector(int n){\n vector<int> ans;\n while(n!=0){\n ans.push_back(n%10);\n n = n/10;\n }\n sort(ans.begin(),ans.end());\n return ans;\n }\n // [5,2,1]\n \n int toInteger(vector<int> &ans){\n int nums = 0;\n for(auto x : ans){\n nums = nums*10 + x;\n }\n return nums;\n }\n bool reorderedPowerOf2(int n) {\n vector<int> vec = tovector(n);\n do{\n if(vec.size() == 1 && vec[0] == 1) return true;\n if(vec[0] == 0 ||((vec[vec.size()-1]%2 ==1))){\n continue;\n }\n int n = toInteger(vec);\n if((n &(n-1)) == 0) return true;\n \n }while(next_permutation(vec.begin(),vec.end()));\n return false;\n }\n \n};\n``` | 2 | 0 | ['C', 'Sorting', 'C++'] | 1 |
reordered-power-of-2 | Ruby: Set of strings. | ruby-set-of-strings-by-user9697n-jl3m | Leetcode: 869. Reordered Power of 2.\n\n\nRuby: Set of strings.\n\n1. Need to get an array of powers of two till 10**9.\n2. Convert these numbers to strings and | user9697n | NORMAL | 2022-08-26T15:55:19.324652+00:00 | 2022-08-26T15:55:19.324696+00:00 | 23 | false | ## Leetcode: 869. Reordered Power of 2.\n\n\n**Ruby: Set of strings.**\n\n1. Need to get an array of powers of two till `10**9`.\n2. Convert these numbers to strings and sort chars. Create a set from the array.\n3. Convert inpur to string sort chars join and check does in include in the set.\n\nLet\'s try.\n\nRuby code:\n```Ruby\n# Leetcode: 869. Reordered Power of 2.\n# https://leetcode.com/problems/reordered-power-of-2/\n# = = = = = = = = = = = = = =\n# Accepted.\n# Thanks God, Jesus Christ!\n# = = = = = = = = = = = = = =\n# Runtime: 82 ms, faster than 100.00% of Ruby online submissions for Reordered Power of 2.\n# Memory Usage: 210.9 MB, less than 100.00% of Ruby online submissions for Reordered Power of 2.\n# @param {Integer} n\n# @return {Boolean}\ndef reordered_power_of2(n)\n require "set"\n @two ||= get_powers_of_2()\n .map{|x| x.to_s.chars.sort.join}.to_set\n @two.include?(n.to_s.chars.sort.join)\nend\n\ndef get_powers_of_2()\n answer = []\n value = 1\n border = 10**9 \n while value <= border\n answer.push value\n value *= 2\n end\n answer\nend\n\n```\n | 2 | 0 | ['Ordered Set', 'Ruby'] | 1 |
reordered-power-of-2 | [JAVA] Simple solution | java-simple-solution-by-priyankan_23-q9tf | \nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n char[] num = getArr(n);\n for (int i = 0; i < 30; ++i) {\n char[] p | priyankan_23 | NORMAL | 2022-08-26T15:40:07.187424+00:00 | 2022-08-26T15:40:07.187466+00:00 | 38 | false | ```\nclass Solution {\n public boolean reorderedPowerOf2(int n) {\n char[] num = getArr(n);\n for (int i = 0; i < 30; ++i) {\n char[] powerOfTwo = getArr(1 << i);\n if (Arrays.equals(num, powerOfTwo))\n return true;\n }\n return false;\n }\n\n public char[] getArr(int n) {\n char[] digits = String.valueOf(n).toCharArray();\n Arrays.sort(digits);\n return digits;\n }\n}\n``` | 2 | 0 | [] | 0 |
reordered-power-of-2 | C++ 0ms Solution | Easy to understand | Short code | c-0ms-solution-easy-to-understand-short-jcq7c | 1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given numb | biswassougato | NORMAL | 2022-08-26T15:31:54.923236+00:00 | 2022-08-26T15:31:54.923266+00:00 | 51 | false | 1) Create a vector of strings "v" of size 30 where each string represents a power of 2 (from 0 to 30) with its digits in sorted form.\n2) Convert the given number to string "s" and sort its digits as well.\n3) Compare the resultant string "s" with each element of the vector of strings "v".\n4) Return true if a match is found else return false.\n\n```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n vector<string> v;\n for(int i=0;i<30;i++)\n {\n int k=pow(2,i);\n string c=to_string(k);\n sort(c.begin(),c.end());\n v.push_back(c);\n }\n string s=to_string(n);\n sort(s.begin(),s.end());\n for(auto it:v)\n {\n if(s==it)\n return true;\n }\n return false;\n }\n};\n```\n | 2 | 0 | ['Math', 'String', 'C', 'Sorting'] | 0 |
reordered-power-of-2 | rust solution | rust-solution-by-radhikagokani-7ju9 | \n\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n let mut log = (n as f32).log2();\n if n == i32::pow(2, log as u32) {\n | radhikagokani | NORMAL | 2022-08-26T10:43:11.732361+00:00 | 2022-08-26T10:43:11.732396+00:00 | 19 | false | ```\n\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n let mut log = (n as f32).log2();\n if n == i32::pow(2, log as u32) {\n return true;\n }\n\n let mut n_s = n.to_string().chars().collect::<Vec<char>>();\n\n n_s.sort();\n\n for i in 0..30 {\n let pow_2 = i64::pow(2, i);\n \n\n let mut pow_2_s = pow_2.to_string().chars().collect::<Vec<char>>();\n\n pow_2_s.sort();\n\n if pow_2_s == n_s {\n println!("found at {}", pow_2);\n return true;\n }\n \n \n }\n\n return false;\n }\n}\n\n``` | 2 | 0 | [] | 0 |
reordered-power-of-2 | [ Python ] ✅✅ Simple Python Solution Using Two Different Approach 🥳✌👍 | python-simple-python-solution-using-two-9fwdl | If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# 1. First Apporach Using Permutation Concept : \n# Runtime: 8288 | ashok_kumar_meghvanshi | NORMAL | 2022-08-26T10:10:05.247804+00:00 | 2022-08-26T10:48:20.368838+00:00 | 470 | false | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# 1. First Apporach Using Permutation Concept : \n# Runtime: 8288 ms, faster than 5.35% of Python3 online submissions for Reordered Power of 2.\n# Memory Usage: 28.1 MB, less than 11.23% of Python3 online submissions for Reordered Power of 2.\n\tclass Solution:\n\t\tdef reorderedPowerOf2(self, n: int) -> bool:\n\n\t\t\tall_permutations = [] \n\n\t\t\tfor single_number in itertools.permutations(str(n)):\n\n\t\t\t\tif single_number[0] != \'0\':\n\n\t\t\t\t\tnum = int(\'\'.join(single_number))\n\n\t\t\t\t\tall_permutations.append(num)\n\n\t\t\tfor i in range(32):\n\n\t\t\t\tif 2**i in all_permutations:\n\t\t\t\t\treturn True\n\n\t\t\treturn False\n# 2. Second Approach With HashMap Or Dictionary with Sorting : \n# Runtime: 56 ms, faster than 60.96% of Python3 online submissions for Reordered Power of 2.\n# Memory Usage: 13.7 MB, less than 96.79% of Python3 online submissions for Reordered Power of 2.\n\n\tclass Solution:\n\t\tdef reorderedPowerOf2(self, n: int) -> bool:\n\n\t\t\tnum = sorted(str(n))\n\n\t\t\tfor i in range(32):\n\n\t\t\t\tcurrent_num = sorted(str(2**i))\n\n\t\t\t\tif num == current_num:\n\t\t\t\t\treturn True\n\n\t\t\treturn False\n# Thank You \uD83E\uDD73\u270C\uD83D\uDC4D | 2 | 0 | ['Sorting', 'Probability and Statistics', 'Python', 'Python3'] | 1 |
reordered-power-of-2 | easy fast solution | easy-fast-solution-by-hurshidbek-atxp | \nPLEASE UPVOTE IF YOU LIKE\n\n```\n char[] car1 = ("" + n).toCharArray(); \n\t\tArrays.sort(car1);\n\n for(int i = 0; i < 30;i++){\n c | Hurshidbek | NORMAL | 2022-08-26T09:08:56.233879+00:00 | 2022-08-26T09:08:56.233920+00:00 | 135 | false | ```\nPLEASE UPVOTE IF YOU LIKE\n```\n```\n char[] car1 = ("" + n).toCharArray(); \n\t\tArrays.sort(car1);\n\n for(int i = 0; i < 30;i++){\n char[] car2 = ("" + (1 << i)).toCharArray(); \n\t\t\tArrays.sort(car2);\n if(Arrays.equals(car1, car2)) return true;\n }\n\n return false; | 2 | 0 | ['Bit Manipulation', 'Java'] | 0 |
reordered-power-of-2 | Asymptotic O(1) - Constant Time Solution || Faster than 100% || Explanation | asymptotic-o1-constant-time-solution-fas-6ucx | \nclass Solution { // 0ms - 100.00% Faster \n static HashSet<String> set;\n Solution(){ // this checks if the set is null, or it computes all the powers o | Lil_ToeTurtle | NORMAL | 2022-08-26T08:28:11.903121+00:00 | 2022-08-26T08:30:08.406658+00:00 | 127 | false | ```\nclass Solution { // 0ms - 100.00% Faster \n static HashSet<String> set;\n Solution(){ // this checks if the set is null, or it computes all the powers of 2 and stores it in the set(this operation occurs only once)\n if(set==null){\n set = new HashSet<String>();\n for(long i=1;i<=1000000000;i=i<<1){\n String s = getFrequencyChart(i);\n set.add(s);\n }\n }\n }\n private String getFrequencyChart(long n){ // this is the function to calculate the frequency of all the digits in the array\n int[] freq = new int[10];\n while(n>0){\n freq[(int)n%10]++;\n n/=10;\n }\n return Arrays.toString(freq);\n }\n \n public boolean reorderedPowerOf2(int n) {\n return set.contains(getFrequencyChart((long)n));\n }\n}\n```\nExplanation:\n* Which we are setting the map as static, it creates only one `set` map object for all the object of the Solution class. Thus reducing the time to recalculate the set\n* `getFrequencyChart generates a frequency map of a number\'s digits and returns it which is used as a hashset key\n* In the Main Function we are just checking if the frequencies of the given numbers matches with the any power of 2.\n\n`Please Upvote if you find it helpful` \uD83D\uDE4F\uD83D\uDE4F | 2 | 0 | ['Ordered Set', 'Java'] | 2 |
reordered-power-of-2 | 100% Faster Solution | 100-faster-solution-by-archittt-tg3y | \n\nclass Solution {\npublic:\n\n bool equal(vector<int>&a,vector<int>&b ){\n for(int i=0;i<10;i++){\n if(a[i]!=b[i])return false;\n | archittt | NORMAL | 2022-08-26T07:26:06.853174+00:00 | 2022-08-30T11:51:45.194981+00:00 | 27 | false | \n```\nclass Solution {\npublic:\n\n bool equal(vector<int>&a,vector<int>&b ){\n for(int i=0;i<10;i++){\n if(a[i]!=b[i])return false;\n }\n return true;\n }\n vector<int> freq(int n){\n vector<int>f(10,0);\n while(n>0){\n f[n%10]++;\n n/=10;\n }\n return f;\n }\n \n bool reorderedPowerOf2(int n) {\n vector<int>a(10,0);\n vector<int>b(10,0);\n a=freq(n);\n for(int i=0;i<31;i++){\n b=freq(pow(2,i));\n if(equal(a,b))return true;\n }\n return false;\n }\n};\n```\n\n\n | 2 | 0 | [] | 2 |
reordered-power-of-2 | Rust | Run-Time One-Liner and the Nerdiest Approach You Will Ever See :-P | With Comments | rust-run-time-one-liner-and-the-nerdiest-pize | So I wasn\'t the only one to think about precomputation here... Anyway, my "standard" solution is below, and then we\'ll go really crazy with an idea I had belo | wallicent | NORMAL | 2022-08-26T07:14:58.066546+00:00 | 2022-08-26T11:48:41.075864+00:00 | 54 | false | So I wasn\'t the only one to think about precomputation here... Anyway, my "standard" solution is below, and then we\'ll go really crazy with an idea I had below that, which you really don\'t want to miss :D.\n\nI love how easy it is to compute things at compile time in Rust compared to C++\'s `constexpr`. So for the "standard" solution I use that to build a look-up table with the digit histograms of all the powers of two <= 10^9 (there are 30). At runtime, I only have to build the histogram of the given number, and check if it is in the lookup table.\n\n**"Standard" Solution**\n\n```\nconst N_DIGITS: usize = 10;\n\nconst fn build_histogram(mut n: i32) -> [u8; N_DIGITS] {\n let mut rez = [0; N_DIGITS];\n while n > 0 {\n rez[(n % 10) as usize] += 1;\n n /= 10;\n }\n rez\n}\n\nconst N_POWERS: usize = 30;\n\nconst fn compute_power_histograms() -> [[u8; N_DIGITS]; N_POWERS] {\n let mut i = 0;\n let mut rez = [[0; N_DIGITS]; N_POWERS];\n while i < N_POWERS {\n rez[i] = build_histogram(1 << i);\n i += 1;\n }\n rez\n}\n\nconst POWER_HISTOGRAMS: [[u8; N_DIGITS]; N_POWERS] = compute_power_histograms();\n\nimpl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n POWER_HISTOGRAMS.contains(&build_histogram(n))\n }\n}\n```\n\n**Graph Solution**\n\nSo, what if we build a graph of all the valid paths we can take given the digits as edges? We\'ll mark whether each node is a valid leaf or not. The result is that when we traverse the graph e.g. 64 and 46 both end up at the same leaf node. The benefit of this approach is that we will be able to weed out a number as soon as we encounter a digit that is not on a valid path, since the tail node won\'t have an edge for the next digit. Compare that to the "standard" solution where we *have* to have all the digits of `n` before checking if it\'s a valid power of two (yeah, yeah, big-O time complexities are the same, but let\'s have some fun :) ) We\'ll use a separate program to compute the graph (I have pasted that in at the very bottom of this post), and we\'ll use the computed graph as a constant that gets compiled into our program for solving the problem. Here is the finished solution (it\'s long :) ):\n\n```\nconst N_DIGITS: usize = 10;\n\nimpl Solution {\n pub fn reordered_power_of2(mut n: i32) -> bool {\n let mut node = 0;\n while n > 0 {\n let digit = (n % 10) as usize;\n match GRAPH[node].0[digit] {\n 0 => return false,\n next_node => node = next_node,\n }\n n /= 10;\n }\n GRAPH[node].1\n }\n}\n\nconst GRAPH: [([usize; N_DIGITS], bool); 1203] = [\n ([31, 1, 2, 7, 3, 17, 5, 87, 4, 38], false),\n ([30, 139, 13, 75, 25, 20, 6, 123, 12, 54], true),\n ([29, 13, 162, 8, 21, 18, 16, 94, 10, 52], true),\n ([27, 25, 21, 73, 154, 184, 9, 261, 32, 43], true),\n ([37, 12, 10, 66, 32, 176, 55, 76, 164, 48], true),\n ([47, 6, 16, 71, 9, 14, 96, 88, 55, 39], false),\n ([273, 460, 153, 72, 70, 269, 457, 250, 62, 1072], true),\n ([136, 75, 8, 512, 73, 107, 71, 92, 66, 363], false),\n ([132, 128, 733, 515, 511, 501, 95, 93, 86, 1082], true),\n ([46, 70, 147, 68, 141, 265, 581, 246, 56, 40], true),\n ([36, 11, 183, 86, 33, 180, 85, 83, 174, 49], false),\n ([1153, 672, 670, 667, 661, 1147, 1138, 649, 0, 50], true),\n ([237, 673, 11, 67, 65, 233, 62, 215, 557, 51], false),\n ([28, 137, 163, 128, 22, 19, 153, 118, 11, 53], false),\n ([271, 269, 15, 104, 265, 102, 97, 238, 218, 1044], false),\n ([1190, 1188, 0, 868, 867, 860, 842, 1162, 792, 1053], true),\n ([1196, 153, 151, 95, 147, 15, 454, 91, 85, 1068], false),\n ([278, 20, 18, 107, 184, 105, 14, 253, 176, 303], false),\n ([338, 19, 187, 501, 185, 482, 15, 322, 180, 304], false),\n ([337, 0, 334, 1197, 0, 0, 1188, 327, 1147, 309], true),\n ([277, 0, 19, 1200, 274, 0, 269, 258, 233, 312], false),\n ([24, 22, 160, 511, 155, 185, 147, 713, 33, 0], false),\n ([23, 731, 161, 727, 158, 0, 150, 717, 661, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 23, 0, 0, 0, 0, 0, 0, 34, 0], false),\n ([26, 732, 22, 74, 159, 274, 70, 262, 65, 361], false),\n ([0, 0, 23, 381, 379, 275, 272, 263, 236, 362], false),\n ([0, 26, 24, 382, 380, 276, 46, 264, 35, 44], false),\n ([0, 138, 339, 131, 23, 337, 1195, 121, 1153, 319], false),\n ([0, 28, 340, 132, 24, 338, 1196, 122, 36, 320], false),\n ([0, 140, 28, 135, 26, 277, 273, 126, 237, 321], false),\n ([0, 30, 29, 136, 27, 278, 47, 127, 37, 45], false),\n ([35, 65, 33, 63, 819, 177, 56, 211, 171, 0], false),\n ([34, 661, 182, 652, 822, 178, 798, 632, 172, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 236, 34, 0, 0, 232, 227, 214, 556, 0], false),\n ([0, 1153, 0, 1151, 34, 1149, 1140, 1124, 0, 993], false),\n ([0, 237, 36, 407, 35, 235, 229, 217, 405, 995], false),\n ([45, 54, 52, 363, 43, 303, 39, 279, 48, 0], false),\n ([42, 1072, 1068, 1060, 40, 1044, 0, 996, 936, 0], false),\n ([41, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 1073, 1071, 1067, 41, 1059, 0, 1027, 967, 0], false),\n ([44, 361, 0, 357, 341, 0, 40, 0, 0, 0], false),\n ([0, 362, 0, 360, 356, 0, 41, 0, 0, 0], false),\n ([0, 321, 320, 366, 44, 314, 42, 302, 995, 0], false),\n ([0, 272, 0, 0, 0, 268, 584, 249, 227, 41], false),\n ([0, 273, 1196, 408, 46, 271, 586, 252, 229, 42], false),\n ([995, 51, 49, 984, 0, 968, 936, 872, 0, 0], false),\n ([993, 50, 0, 985, 0, 977, 961, 929, 0, 0], false),\n ([992, 0, 0, 986, 0, 978, 962, 930, 0, 0], true),\n ([994, 0, 50, 989, 0, 981, 965, 933, 0, 0], false),\n ([320, 53, 315, 1082, 0, 304, 1068, 292, 49, 0], false),\n ([319, 0, 316, 1083, 0, 309, 1069, 297, 50, 0], false),\n ([321, 0, 53, 364, 361, 312, 1072, 300, 51, 0], false),\n ([229, 62, 85, 60, 56, 218, 567, 77, 399, 936], false),\n ([227, 59, 798, 57, 793, 219, 568, 196, 548, 0], false),\n ([0, 58, 797, 0, 794, 787, 765, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([226, 0, 0, 58, 0, 220, 569, 197, 549, 0], false),\n ([406, 61, 84, 0, 57, 790, 768, 78, 400, 953], false),\n ([1137, 0, 1134, 0, 58, 1128, 0, 1101, 0, 958], false),\n ([228, 0, 1138, 61, 59, 223, 572, 200, 552, 965], false),\n ([0, 64, 652, 0, 820, 815, 57, 623, 0, 0], false),\n ([0, 658, 656, 0, 0, 0, 58, 630, 0, 0], false),\n ([236, 663, 661, 64, 0, 230, 59, 212, 554, 0], false),\n ([407, 67, 86, 0, 63, 817, 60, 81, 403, 984], false),\n ([1152, 669, 667, 0, 64, 1144, 61, 644, 0, 989], false),\n ([0, 69, 871, 0, 869, 865, 847, 0, 57, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 58, 0], false),\n ([272, 0, 150, 69, 146, 266, 582, 247, 59, 0], false),\n ([408, 72, 95, 0, 68, 104, 101, 89, 60, 1060], false),\n ([1194, 0, 1191, 0, 69, 1185, 0, 1169, 61, 1065], false),\n ([382, 74, 511, 507, 375, 491, 68, 704, 63, 357], false),\n ([381, 729, 727, 0, 376, 0, 69, 711, 64, 358], false),\n ([135, 133, 128, 0, 74, 1200, 72, 113, 67, 364], false),\n ([217, 215, 83, 81, 211, 203, 77, 587, 516, 872], false),\n ([202, 200, 80, 78, 196, 188, 559, 0, 517, 873], false),\n ([1103, 1101, 79, 0, 0, 1086, 0, 0, 0, 890], false),\n ([1100, 1098, 0, 0, 0, 1087, 0, 0, 0, 891], true),\n ([1106, 1104, 0, 79, 0, 1094, 0, 0, 0, 898], false),\n ([1122, 644, 82, 0, 623, 1107, 78, 606, 0, 921], false),\n ([1120, 642, 639, 0, 624, 1108, 79, 607, 0, 922], false),\n ([1124, 649, 646, 82, 632, 1115, 80, 615, 0, 929], false),\n ([1136, 1134, 0, 0, 797, 791, 769, 79, 0, 954], false),\n ([1140, 1138, 0, 84, 798, 792, 770, 80, 0, 961], false),\n ([1151, 667, 664, 0, 652, 818, 84, 82, 0, 985], false),\n ([127, 123, 94, 92, 261, 253, 88, 409, 76, 279], false),\n ([252, 250, 91, 89, 246, 238, 445, 428, 77, 996], false),\n ([1171, 1169, 90, 0, 0, 1154, 0, 0, 78, 1013], false),\n ([1168, 1166, 0, 0, 0, 1155, 0, 0, 79, 1014], false),\n ([1173, 451, 0, 90, 0, 1162, 446, 435, 80, 1021], false),\n ([117, 113, 93, 0, 704, 1174, 89, 692, 81, 1036], false),\n ([112, 108, 720, 0, 705, 1175, 90, 693, 82, 1037], false),\n ([122, 118, 330, 93, 713, 322, 91, 440, 83, 292], false),\n ([1193, 1191, 0, 0, 871, 868, 850, 90, 84, 1061], false),\n ([586, 457, 454, 101, 581, 97, 0, 445, 567, 0], false),\n ([0, 0, 842, 100, 833, 98, 0, 0, 737, 0], false),\n ([0, 0, 832, 99, 823, 0, 0, 0, 738, 0], false),\n ([0, 0, 831, 0, 828, 0, 0, 0, 747, 0], true),\n ([0, 0, 841, 0, 838, 99, 0, 0, 758, 0], false),\n ([0, 0, 850, 0, 847, 100, 0, 0, 768, 0], false),\n ([0, 0, 860, 103, 851, 0, 98, 0, 771, 0], false),\n ([0, 0, 859, 0, 856, 0, 99, 0, 780, 0], false),\n ([1187, 1185, 868, 0, 865, 103, 100, 1154, 790, 1045], false),\n ([0, 0, 482, 106, 461, 0, 102, 0, 799, 0], false),\n ([0, 0, 481, 477, 470, 0, 103, 0, 808, 0], false),\n (\n [1202, 1200, 501, 497, 491, 106, 104, 1174, 817, 1074],\n false,\n ),\n ([111, 109, 721, 0, 709, 1176, 1166, 697, 642, 1038], false),\n ([110, 0, 722, 0, 710, 0, 0, 698, 643, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 110, 0, 0, 0, 1177, 1167, 0, 1119, 1039], false),\n ([0, 111, 0, 0, 0, 1178, 1168, 0, 1120, 1040], false),\n ([116, 114, 108, 0, 711, 1179, 1169, 699, 644, 1041], false),\n ([115, 0, 109, 0, 712, 0, 0, 700, 645, 0], false),\n ([0, 0, 110, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 115, 111, 0, 0, 1180, 1170, 0, 1121, 1042], false),\n ([0, 116, 112, 0, 0, 1181, 1171, 0, 1122, 1043], false),\n ([121, 119, 331, 108, 717, 327, 451, 441, 649, 297], false),\n ([120, 0, 723, 109, 718, 0, 452, 442, 650, 0], false),\n ([0, 0, 0, 110, 0, 0, 0, 0, 0, 0], false),\n ([0, 120, 332, 111, 0, 328, 1172, 0, 1123, 298], false),\n ([0, 121, 333, 112, 0, 329, 1173, 0, 1124, 299], false),\n ([126, 124, 118, 113, 262, 258, 250, 443, 215, 300], false),\n ([125, 0, 119, 114, 719, 0, 453, 444, 651, 0], false),\n ([0, 0, 120, 115, 0, 0, 0, 0, 0, 0], false),\n ([0, 125, 121, 116, 263, 259, 251, 0, 216, 301], false),\n ([0, 126, 122, 117, 264, 260, 252, 0, 217, 302], false),\n ([131, 129, 734, 0, 727, 1197, 1191, 108, 667, 1083], false),\n ([130, 0, 735, 0, 728, 0, 0, 109, 668, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 110, 0, 0], false),\n ([0, 130, 0, 0, 0, 1198, 1192, 111, 1150, 1084], false),\n ([0, 131, 0, 0, 0, 1199, 1193, 112, 1151, 1085], false),\n ([134, 0, 129, 0, 729, 0, 0, 114, 669, 0], false),\n ([0, 0, 130, 0, 0, 0, 0, 115, 0, 0], false),\n ([0, 134, 131, 0, 381, 1201, 1194, 116, 1152, 365], false),\n ([0, 135, 132, 0, 382, 1202, 408, 117, 407, 366], false),\n ([138, 0, 736, 129, 731, 0, 459, 119, 672, 0], false),\n ([0, 0, 0, 130, 0, 0, 0, 120, 0, 0], false),\n ([140, 0, 137, 133, 732, 0, 460, 124, 673, 0], false),\n ([0, 0, 138, 134, 0, 0, 0, 125, 0, 0], false),\n ([0, 146, 142, 869, 0, 861, 843, 0, 793, 0], false),\n ([0, 145, 143, 870, 0, 864, 846, 0, 796, 0], false),\n ([0, 144, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 0, 144, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 145, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 150, 148, 871, 142, 867, 849, 0, 798, 0], false),\n ([0, 149, 0, 0, 143, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 144, 0, 0, 0, 0, 0], false),\n ([0, 0, 149, 0, 145, 0, 0, 0, 0, 0], false),\n ([0, 152, 0, 0, 148, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 149, 0, 0, 0, 0, 0], false),\n (\n [1195, 459, 152, 1191, 150, 1188, 455, 451, 1138, 1069],\n false,\n ),\n ([380, 159, 155, 375, 367, 483, 141, 0, 819, 341], false),\n ([0, 158, 156, 506, 0, 490, 142, 0, 822, 0], false),\n ([0, 157, 0, 0, 0, 0, 143, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 144, 0, 0, 0], false),\n ([0, 0, 157, 0, 0, 0, 145, 0, 0, 0], false),\n ([379, 0, 158, 376, 372, 0, 146, 0, 0, 354], false),\n ([0, 161, 0, 724, 156, 186, 148, 714, 182, 0], false),\n ([0, 730, 0, 725, 157, 0, 149, 715, 659, 0], false),\n ([340, 163, 0, 733, 160, 187, 151, 330, 183, 315], false),\n ([339, 736, 0, 734, 161, 334, 152, 331, 670, 316], false),\n ([405, 557, 174, 403, 171, 165, 399, 516, 383, 0], false),\n ([0, 0, 169, 0, 166, 0, 0, 0, 0, 0], false),\n ([0, 0, 167, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 168, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 0, 170, 0, 167, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 168, 0, 0, 0, 0, 0], false),\n ([556, 554, 172, 0, 0, 166, 548, 533, 0, 0], false),\n ([0, 0, 173, 0, 0, 167, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 168, 0, 0, 0, 0], false),\n ([0, 0, 175, 0, 172, 169, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 173, 170, 0, 0, 0, 0], false),\n ([235, 233, 180, 817, 177, 799, 218, 203, 165, 968], false),\n ([232, 230, 178, 815, 811, 800, 219, 204, 166, 0], false),\n ([0, 0, 179, 816, 814, 807, 789, 0, 167, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 168, 0], false),\n ([1149, 1147, 181, 818, 178, 810, 792, 1115, 169, 977], false),\n ([0, 0, 0, 0, 179, 0, 0, 0, 170, 0], false),\n ([0, 659, 0, 653, 0, 179, 0, 633, 173, 0], false),\n ([0, 670, 0, 664, 182, 181, 0, 646, 175, 0], false),\n ([276, 274, 185, 491, 483, 461, 265, 254, 177, 0], false),\n ([0, 0, 186, 496, 490, 476, 867, 0, 178, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 179, 0], false),\n ([336, 334, 0, 0, 186, 0, 0, 323, 181, 305], false),\n ([195, 193, 1094, 1086, 189, 0, 0, 0, 0, 874], false),\n ([192, 190, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([191, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 191, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([194, 0, 1095, 1091, 190, 0, 0, 0, 0, 887], false),\n ([0, 0, 1096, 1092, 191, 0, 0, 0, 0, 888], false),\n ([0, 194, 1097, 1093, 192, 0, 0, 0, 0, 889], false),\n ([199, 197, 0, 0, 0, 189, 560, 0, 526, 0], false),\n ([198, 0, 0, 0, 0, 190, 561, 0, 527, 0], false),\n ([0, 0, 0, 0, 0, 191, 562, 0, 528, 0], false),\n ([0, 198, 0, 0, 0, 192, 563, 0, 529, 0], false),\n ([201, 0, 1104, 1101, 197, 193, 564, 0, 530, 902], false),\n ([0, 0, 1105, 1102, 198, 194, 565, 0, 531, 903], false),\n ([0, 201, 1106, 1103, 199, 195, 566, 0, 532, 904], false),\n ([210, 208, 1115, 1107, 204, 0, 188, 0, 0, 905], false),\n ([207, 205, 0, 0, 0, 0, 189, 0, 0, 0], false),\n ([206, 0, 0, 0, 0, 0, 190, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 191, 0, 0, 0], false),\n ([0, 206, 0, 0, 0, 0, 192, 0, 0, 0], false),\n ([209, 0, 1116, 1112, 205, 0, 193, 0, 0, 918], false),\n ([0, 0, 1117, 1113, 206, 0, 194, 0, 0, 919], false),\n ([0, 209, 1118, 1114, 207, 0, 195, 0, 0, 920], false),\n ([214, 212, 632, 623, 0, 204, 196, 588, 533, 0], false),\n ([213, 638, 636, 630, 0, 205, 197, 604, 534, 0], false),\n ([0, 0, 0, 0, 0, 206, 198, 0, 535, 0], false),\n ([0, 213, 0, 0, 0, 207, 199, 0, 536, 0], false),\n ([216, 651, 649, 644, 212, 208, 200, 621, 537, 933], false),\n ([0, 0, 1123, 1121, 213, 209, 201, 0, 538, 934], false),\n ([0, 216, 1124, 1122, 214, 210, 202, 0, 539, 935], false),\n ([225, 223, 792, 790, 219, 771, 737, 188, 0, 937], false),\n ([222, 220, 789, 787, 783, 772, 750, 189, 0, 0], false),\n ([221, 0, 0, 0, 0, 0, 0, 190, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 191, 0, 0], false),\n ([0, 221, 0, 0, 0, 0, 0, 192, 0, 0], false),\n ([224, 0, 1131, 1128, 220, 0, 0, 193, 0, 950], false),\n ([0, 0, 1132, 1129, 221, 0, 0, 194, 0, 951], false),\n ([0, 224, 1133, 1130, 222, 0, 0, 195, 0, 952], false),\n ([0, 0, 0, 0, 0, 221, 570, 198, 550, 0], false),\n ([0, 226, 0, 0, 0, 222, 571, 199, 551, 0], false),\n ([0, 0, 1139, 1137, 226, 224, 573, 201, 553, 966], false),\n ([0, 228, 1140, 406, 227, 225, 574, 202, 402, 967], false),\n ([231, 0, 0, 0, 0, 0, 220, 205, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 221, 206, 0, 0], false),\n ([0, 231, 0, 0, 0, 0, 222, 207, 0, 0], false),\n ([234, 0, 1147, 1144, 230, 0, 223, 208, 0, 981], false),\n ([0, 0, 1148, 1145, 231, 0, 224, 209, 0, 982], false),\n ([0, 234, 1149, 1146, 232, 0, 225, 210, 0, 983], false),\n ([0, 0, 0, 0, 0, 231, 226, 213, 555, 0], false),\n ([0, 0, 1153, 1152, 236, 234, 228, 216, 558, 994], false),\n ([245, 243, 1162, 1154, 239, 0, 0, 0, 188, 997], false),\n ([242, 240, 0, 0, 0, 0, 0, 0, 189, 0], false),\n ([241, 0, 0, 0, 0, 0, 0, 0, 190, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 191, 0], false),\n ([0, 241, 0, 0, 0, 0, 0, 0, 192, 0], false),\n ([244, 0, 1163, 1159, 240, 0, 0, 0, 193, 1010], false),\n ([0, 0, 1164, 1160, 241, 0, 0, 0, 194, 1011], false),\n ([0, 244, 1165, 1161, 242, 0, 0, 0, 195, 1012], false),\n ([249, 247, 0, 0, 0, 239, 575, 0, 196, 0], false),\n ([248, 0, 0, 0, 0, 240, 576, 0, 197, 0], false),\n ([0, 0, 0, 0, 0, 241, 577, 0, 198, 0], false),\n ([0, 248, 0, 0, 0, 242, 578, 0, 199, 0], false),\n ([251, 453, 451, 1169, 247, 243, 449, 438, 200, 1025], false),\n ([0, 0, 1172, 1170, 248, 244, 579, 0, 201, 1026], false),\n ([0, 251, 1173, 1171, 249, 245, 580, 0, 202, 1027], false),\n ([260, 258, 322, 1174, 254, 0, 238, 0, 203, 280], false),\n ([257, 255, 0, 0, 0, 0, 239, 0, 204, 0], false),\n ([256, 0, 0, 0, 0, 0, 240, 0, 205, 0], false),\n ([0, 0, 0, 0, 0, 0, 241, 0, 206, 0], false),\n ([0, 256, 0, 0, 0, 0, 242, 0, 207, 0], false),\n ([259, 0, 327, 1179, 255, 0, 243, 0, 208, 289], false),\n ([0, 0, 328, 1180, 256, 0, 244, 0, 209, 290], false),\n ([0, 259, 329, 1181, 257, 0, 245, 0, 210, 291], false),\n ([264, 262, 713, 704, 0, 254, 246, 674, 211, 0], false),\n ([263, 719, 717, 711, 0, 255, 247, 690, 212, 0], false),\n ([0, 0, 0, 0, 0, 256, 248, 0, 213, 0], false),\n ([0, 263, 0, 0, 0, 257, 249, 0, 214, 0], false),\n ([268, 266, 867, 865, 861, 851, 833, 239, 219, 0], false),\n ([267, 0, 0, 0, 0, 0, 0, 240, 220, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 241, 221, 0], false),\n ([0, 267, 0, 0, 0, 0, 0, 242, 222, 0], false),\n ([270, 0, 1188, 1185, 266, 0, 0, 243, 223, 1057], false),\n ([0, 0, 1189, 1186, 267, 0, 0, 244, 224, 1058], false),\n ([0, 270, 1190, 1187, 268, 0, 0, 245, 225, 1059], false),\n ([0, 0, 0, 0, 0, 267, 583, 248, 226, 0], false),\n ([0, 0, 1195, 1194, 272, 270, 585, 251, 228, 1073], false),\n ([275, 0, 0, 0, 0, 0, 266, 255, 230, 0], false),\n ([0, 0, 0, 0, 0, 0, 267, 256, 231, 0], false),\n ([0, 275, 0, 0, 0, 0, 268, 257, 232, 0], false),\n ([0, 0, 337, 1201, 275, 0, 270, 259, 234, 313], false),\n ([0, 277, 338, 1202, 276, 0, 271, 260, 235, 314], false),\n ([302, 300, 292, 1036, 0, 280, 996, 0, 872, 0], false),\n ([291, 289, 281, 1028, 0, 0, 997, 0, 905, 0], false),\n ([288, 286, 282, 1029, 0, 0, 1006, 0, 914, 0], false),\n ([285, 283, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([284, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 284, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([287, 0, 283, 1030, 0, 0, 1007, 0, 915, 0], false),\n ([0, 0, 284, 1031, 0, 0, 1008, 0, 916, 0], false),\n ([0, 287, 285, 1032, 0, 0, 1009, 0, 917, 0], false),\n ([290, 0, 286, 1033, 0, 0, 1010, 0, 918, 0], false),\n ([0, 0, 287, 1034, 0, 0, 1011, 0, 919, 0], false),\n ([0, 290, 288, 1035, 0, 0, 1012, 0, 920, 0], false),\n ([299, 297, 293, 1037, 0, 281, 1021, 0, 929, 0], false),\n ([296, 294, 0, 0, 0, 282, 0, 0, 0, 0], false),\n ([295, 0, 0, 0, 0, 283, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 284, 0, 0, 0, 0], false),\n ([0, 295, 0, 0, 0, 285, 0, 0, 0, 0], false),\n ([298, 0, 294, 1038, 0, 286, 1022, 0, 930, 0], false),\n ([0, 0, 295, 1039, 0, 287, 1023, 0, 931, 0], false),\n ([0, 298, 296, 1040, 0, 288, 1024, 0, 932, 0], false),\n ([301, 0, 297, 1041, 0, 289, 1025, 0, 933, 0], false),\n ([0, 0, 298, 1042, 0, 290, 1026, 0, 934, 0], false),\n ([0, 301, 299, 1043, 0, 291, 1027, 0, 935, 0], false),\n ([314, 312, 304, 1074, 0, 0, 1044, 280, 968, 0], false),\n ([311, 309, 305, 1075, 0, 0, 1053, 281, 977, 0], false),\n ([308, 306, 0, 0, 0, 0, 0, 282, 0, 0], false),\n ([307, 0, 0, 0, 0, 0, 0, 283, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 284, 0, 0], false),\n ([0, 307, 0, 0, 0, 0, 0, 285, 0, 0], false),\n ([310, 0, 306, 1076, 0, 0, 1054, 286, 978, 0], false),\n ([0, 0, 307, 1077, 0, 0, 1055, 287, 979, 0], false),\n ([0, 310, 308, 1078, 0, 0, 1056, 288, 980, 0], false),\n ([313, 0, 309, 1079, 0, 0, 1057, 289, 981, 0], false),\n ([0, 0, 310, 1080, 0, 0, 1058, 290, 982, 0], false),\n ([0, 313, 311, 1081, 0, 0, 1059, 291, 983, 0], false),\n ([318, 316, 0, 0, 0, 305, 0, 293, 0, 0], false),\n ([317, 0, 0, 0, 0, 306, 0, 294, 0, 0], false),\n ([0, 0, 0, 0, 0, 307, 0, 295, 0, 0], false),\n ([0, 317, 0, 0, 0, 308, 0, 296, 0, 0], false),\n ([0, 0, 317, 1084, 0, 310, 1070, 298, 992, 0], false),\n ([0, 319, 318, 1085, 0, 311, 1071, 299, 993, 0], false),\n ([0, 0, 319, 365, 362, 313, 1073, 301, 994, 0], false),\n ([329, 327, 323, 1175, 0, 0, 1162, 0, 1115, 281], false),\n ([326, 324, 0, 0, 0, 0, 0, 0, 0, 282], false),\n ([325, 0, 0, 0, 0, 0, 0, 0, 0, 283], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 284], false),\n ([0, 325, 0, 0, 0, 0, 0, 0, 0, 285], false),\n ([328, 0, 324, 1176, 0, 0, 1163, 0, 1116, 286], false),\n ([0, 0, 325, 1177, 0, 0, 1164, 0, 1117, 287], false),\n ([0, 328, 326, 1178, 0, 0, 1165, 0, 1118, 288], false),\n ([333, 331, 0, 720, 714, 323, 0, 701, 646, 293], false),\n ([332, 723, 0, 721, 715, 324, 0, 702, 647, 294], false),\n ([0, 0, 0, 0, 0, 325, 0, 0, 0, 295], false),\n ([0, 332, 0, 0, 0, 326, 0, 0, 0, 296], false),\n ([335, 0, 0, 0, 0, 0, 0, 324, 0, 306], false),\n ([0, 0, 0, 0, 0, 0, 0, 325, 0, 307], false),\n ([0, 335, 0, 0, 0, 0, 0, 326, 0, 308], false),\n ([0, 0, 335, 1198, 0, 0, 1189, 328, 1148, 310], false),\n ([0, 337, 336, 1199, 0, 0, 1190, 329, 1149, 311], false),\n ([0, 0, 0, 0, 0, 335, 0, 332, 0, 317], false),\n ([0, 339, 0, 0, 0, 336, 0, 333, 0, 318], false),\n ([356, 354, 0, 350, 342, 0, 0, 0, 0, 0], false),\n ([349, 347, 0, 343, 0, 0, 0, 0, 0, 0], false),\n ([346, 344, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([345, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 345, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([348, 0, 0, 344, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 345, 0, 0, 0, 0, 0, 0], false),\n ([0, 348, 0, 346, 0, 0, 0, 0, 0, 0], false),\n ([353, 351, 0, 0, 343, 0, 0, 0, 0, 0], false),\n ([352, 0, 0, 0, 344, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 345, 0, 0, 0, 0, 0], false),\n ([0, 352, 0, 0, 346, 0, 0, 0, 0, 0], false),\n ([355, 0, 0, 351, 347, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 352, 348, 0, 0, 0, 0, 0], false),\n ([0, 355, 0, 353, 349, 0, 0, 0, 0, 0], false),\n ([360, 358, 0, 0, 350, 0, 0, 0, 0, 0], false),\n ([359, 0, 0, 0, 351, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 352, 0, 0, 0, 0, 0], false),\n ([0, 359, 0, 0, 353, 0, 0, 0, 0, 0], false),\n ([362, 0, 0, 358, 354, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 359, 355, 0, 0, 0, 0, 0], false),\n ([366, 364, 1082, 0, 357, 1074, 1060, 1036, 984, 0], false),\n ([365, 0, 1083, 0, 358, 1079, 1065, 1041, 989, 0], false),\n ([0, 0, 1084, 0, 359, 1080, 1066, 1042, 990, 0], false),\n ([0, 365, 1085, 0, 360, 1081, 1067, 1043, 991, 0], false),\n ([374, 372, 0, 368, 0, 0, 0, 0, 0, 342], false),\n ([371, 369, 0, 0, 0, 0, 0, 0, 0, 343], false),\n ([370, 0, 0, 0, 0, 0, 0, 0, 0, 344], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 345], false),\n ([0, 370, 0, 0, 0, 0, 0, 0, 0, 346], false),\n ([373, 0, 0, 369, 0, 0, 0, 0, 0, 347], false),\n ([0, 0, 0, 370, 0, 0, 0, 0, 0, 348], false),\n ([0, 373, 0, 371, 0, 0, 0, 0, 0, 349], false),\n ([378, 376, 506, 502, 368, 484, 869, 0, 820, 350], false),\n ([377, 0, 0, 0, 369, 0, 0, 0, 0, 351], false),\n ([0, 0, 0, 0, 370, 0, 0, 0, 0, 352], false),\n ([0, 377, 0, 0, 371, 0, 0, 0, 0, 353], false),\n ([0, 0, 0, 377, 373, 0, 0, 0, 0, 355], false),\n ([0, 379, 0, 378, 374, 0, 0, 0, 0, 356], false),\n ([0, 0, 0, 0, 377, 0, 0, 0, 0, 359], false),\n ([0, 381, 0, 0, 378, 0, 0, 0, 0, 360], false),\n ([398, 0, 0, 396, 0, 0, 392, 0, 384, 0], false),\n ([391, 0, 0, 389, 0, 0, 385, 0, 0, 0], false),\n ([388, 0, 0, 386, 0, 0, 0, 0, 0, 0], false),\n ([387, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 0, 0, 387, 0, 0, 0, 0, 0, 0], false),\n ([390, 0, 0, 0, 0, 0, 386, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 387, 0, 0, 0], false),\n ([0, 0, 0, 390, 0, 0, 388, 0, 0, 0], false),\n ([395, 0, 0, 393, 0, 0, 0, 0, 385, 0], false),\n ([394, 0, 0, 0, 0, 0, 0, 0, 386, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 387, 0], false),\n ([0, 0, 0, 394, 0, 0, 0, 0, 388, 0], false),\n ([397, 0, 0, 0, 0, 0, 393, 0, 389, 0], false),\n ([0, 0, 0, 0, 0, 0, 394, 0, 390, 0], false),\n ([0, 0, 0, 397, 0, 0, 395, 0, 391, 0], false),\n ([402, 552, 0, 400, 548, 0, 540, 517, 392, 0], false),\n ([401, 0, 0, 0, 0, 0, 0, 0, 393, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 394, 0], false),\n ([0, 553, 0, 401, 551, 0, 547, 532, 395, 0], false),\n ([404, 0, 0, 0, 0, 0, 400, 0, 396, 0], false),\n ([0, 0, 0, 0, 0, 0, 401, 0, 397, 0], false),\n ([0, 558, 0, 404, 556, 0, 402, 539, 398, 0], false),\n ([0, 1137, 1136, 0, 0, 1130, 0, 1103, 401, 960], false),\n ([0, 1152, 1151, 0, 0, 1146, 406, 1122, 404, 991], false),\n ([0, 1194, 1193, 0, 0, 1187, 0, 1171, 406, 1067], false),\n ([0, 443, 440, 692, 674, 0, 428, 410, 587, 0], false),\n ([0, 426, 423, 0, 0, 0, 411, 0, 0, 0], false),\n ([0, 421, 418, 0, 0, 0, 412, 0, 0, 0], false),\n ([0, 416, 413, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 414, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 415, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 417, 414, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 415, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 419, 0, 0, 0, 0, 413, 0, 0, 0], false),\n ([0, 420, 0, 0, 0, 0, 414, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 415, 0, 0, 0], false),\n ([0, 422, 419, 0, 0, 0, 416, 0, 0, 0], false),\n ([0, 0, 420, 0, 0, 0, 417, 0, 0, 0], false),\n ([0, 424, 0, 0, 0, 0, 418, 0, 0, 0], false),\n ([0, 425, 0, 0, 0, 0, 419, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 420, 0, 0, 0], false),\n ([0, 427, 424, 0, 0, 0, 421, 0, 0, 0], false),\n ([0, 0, 425, 0, 0, 0, 422, 0, 0, 0], false),\n ([0, 438, 435, 0, 0, 0, 429, 411, 0, 0], false),\n ([0, 433, 430, 0, 0, 0, 0, 412, 0, 0], false),\n ([0, 431, 0, 0, 0, 0, 0, 413, 0, 0], false),\n ([0, 432, 0, 0, 0, 0, 0, 414, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 415, 0, 0], false),\n ([0, 434, 431, 0, 0, 0, 0, 416, 0, 0], false),\n ([0, 0, 432, 0, 0, 0, 0, 417, 0, 0], false),\n ([0, 436, 0, 0, 0, 0, 430, 418, 0, 0], false),\n ([0, 437, 0, 0, 0, 0, 431, 419, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 432, 420, 0, 0], false),\n ([0, 439, 436, 0, 0, 0, 433, 421, 0, 0], false),\n ([0, 0, 437, 0, 0, 0, 434, 422, 0, 0], false),\n ([0, 441, 701, 693, 684, 0, 435, 423, 615, 0], false),\n ([0, 442, 702, 697, 688, 0, 436, 424, 619, 0], false),\n ([0, 0, 703, 698, 689, 0, 437, 425, 620, 0], false),\n ([0, 444, 441, 699, 690, 0, 438, 426, 621, 0], false),\n ([0, 0, 442, 700, 691, 0, 439, 427, 622, 0], false),\n ([580, 449, 446, 0, 575, 0, 0, 429, 559, 0], false),\n ([0, 447, 0, 0, 0, 0, 0, 430, 0, 0], false),\n ([0, 448, 0, 0, 0, 0, 0, 431, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 432, 0, 0], false),\n ([579, 450, 447, 0, 576, 0, 0, 433, 564, 0], false),\n ([0, 0, 448, 0, 0, 0, 0, 434, 0, 0], false),\n ([1172, 452, 0, 1166, 0, 1163, 447, 436, 1104, 1022], false),\n ([0, 0, 0, 0, 0, 0, 448, 437, 0, 0], false),\n ([0, 0, 452, 0, 0, 0, 450, 439, 0, 0], false),\n ([0, 455, 0, 850, 849, 842, 0, 446, 770, 0], false),\n ([0, 456, 0, 0, 0, 0, 0, 447, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 448, 0, 0], false),\n ([585, 458, 455, 0, 582, 0, 0, 449, 572, 0], false),\n ([0, 0, 456, 0, 0, 0, 0, 450, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 456, 452, 0, 0], false),\n ([0, 0, 459, 0, 0, 0, 458, 453, 0, 0], false),\n ([0, 0, 476, 470, 462, 0, 851, 0, 800, 0], false),\n ([0, 0, 469, 463, 0, 0, 852, 0, 801, 0], false),\n ([0, 0, 468, 464, 0, 0, 853, 0, 802, 0], false),\n ([0, 0, 467, 465, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 466, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 0, 0, 466, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 467, 0, 0, 854, 0, 803, 0], false),\n ([0, 0, 0, 468, 0, 0, 855, 0, 804, 0], false),\n ([0, 0, 475, 471, 463, 0, 856, 0, 805, 0], false),\n ([0, 0, 474, 472, 464, 0, 0, 0, 0, 0], false),\n ([0, 0, 473, 0, 465, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 466, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 473, 467, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 474, 468, 0, 857, 0, 806, 0], false),\n ([0, 0, 0, 475, 469, 0, 858, 0, 807, 0], false),\n ([0, 0, 480, 478, 471, 0, 0, 0, 0, 0], false),\n ([0, 0, 479, 0, 472, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 473, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 479, 474, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 480, 475, 0, 859, 0, 809, 0], false),\n ([0, 0, 0, 481, 476, 0, 860, 0, 810, 0], false),\n ([0, 0, 490, 484, 0, 462, 861, 0, 811, 0], false),\n ([0, 0, 489, 485, 0, 463, 862, 0, 812, 0], false),\n ([0, 0, 488, 486, 0, 464, 0, 0, 0, 0], false),\n ([0, 0, 487, 0, 0, 465, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 466, 0, 0, 0, 0], false),\n ([0, 0, 0, 487, 0, 467, 0, 0, 0, 0], false),\n ([0, 0, 0, 488, 0, 468, 863, 0, 813, 0], false),\n ([0, 0, 0, 489, 0, 469, 864, 0, 814, 0], false),\n ([0, 0, 496, 492, 484, 470, 865, 0, 815, 0], false),\n ([0, 0, 495, 493, 485, 471, 0, 0, 0, 0], false),\n ([0, 0, 494, 0, 486, 472, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 487, 473, 0, 0, 0, 0], false),\n ([0, 0, 0, 494, 488, 474, 0, 0, 0, 0], false),\n ([0, 0, 0, 495, 489, 475, 866, 0, 816, 0], false),\n ([0, 0, 500, 498, 492, 477, 0, 0, 0, 0], false),\n ([0, 0, 499, 0, 493, 478, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 494, 479, 0, 0, 0, 0], false),\n ([0, 0, 0, 499, 495, 480, 0, 0, 0, 0], false),\n ([1199, 1197, 0, 500, 496, 481, 868, 1175, 818, 1075], false),\n ([0, 0, 505, 503, 0, 485, 0, 0, 0, 0], false),\n ([0, 0, 504, 0, 0, 486, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 487, 0, 0, 0, 0], false),\n ([0, 0, 0, 504, 0, 488, 0, 0, 0, 0], false),\n ([0, 0, 0, 505, 0, 489, 870, 0, 821, 0], false),\n ([0, 0, 510, 508, 502, 492, 0, 0, 0, 0], false),\n ([0, 0, 509, 0, 503, 493, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 504, 494, 0, 0, 0, 0], false),\n ([0, 0, 0, 509, 505, 495, 0, 0, 0, 0], false),\n ([0, 727, 724, 510, 506, 496, 871, 705, 652, 0], false),\n ([0, 0, 515, 513, 507, 497, 0, 0, 0, 0], false),\n ([0, 0, 514, 0, 508, 498, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 509, 499, 0, 0, 0, 0], false),\n ([0, 0, 0, 514, 510, 500, 0, 0, 0, 0], false),\n ([539, 537, 0, 0, 533, 0, 517, 0, 0, 0], false),\n ([532, 530, 0, 0, 526, 0, 518, 0, 0, 0], false),\n ([525, 523, 0, 0, 519, 0, 0, 0, 0, 0], false),\n ([522, 520, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([521, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 521, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([524, 0, 0, 0, 520, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 521, 0, 0, 0, 0, 0], false),\n ([0, 524, 0, 0, 522, 0, 0, 0, 0, 0], false),\n ([529, 527, 0, 0, 0, 0, 519, 0, 0, 0], false),\n ([528, 0, 0, 0, 0, 0, 520, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 521, 0, 0, 0], false),\n ([0, 528, 0, 0, 0, 0, 522, 0, 0, 0], false),\n ([531, 0, 0, 0, 527, 0, 523, 0, 0, 0], false),\n ([0, 0, 0, 0, 528, 0, 524, 0, 0, 0], false),\n ([0, 531, 0, 0, 529, 0, 525, 0, 0, 0], false),\n ([536, 534, 0, 0, 0, 0, 526, 0, 0, 0], false),\n ([535, 0, 0, 0, 0, 0, 527, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 528, 0, 0, 0], false),\n ([0, 535, 0, 0, 0, 0, 529, 0, 0, 0], false),\n ([538, 0, 0, 0, 534, 0, 530, 0, 0, 0], false),\n ([0, 0, 0, 0, 535, 0, 531, 0, 0, 0], false),\n ([0, 538, 0, 0, 536, 0, 532, 0, 0, 0], false),\n ([547, 545, 0, 0, 541, 0, 0, 518, 0, 0], false),\n ([544, 542, 0, 0, 0, 0, 0, 519, 0, 0], false),\n ([543, 0, 0, 0, 0, 0, 0, 520, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 521, 0, 0], false),\n ([0, 543, 0, 0, 0, 0, 0, 522, 0, 0], false),\n ([546, 0, 0, 0, 542, 0, 0, 523, 0, 0], false),\n ([0, 0, 0, 0, 543, 0, 0, 524, 0, 0], false),\n ([0, 546, 0, 0, 544, 0, 0, 525, 0, 0], false),\n ([551, 549, 0, 0, 0, 0, 541, 526, 0, 0], false),\n ([550, 0, 0, 0, 0, 0, 542, 527, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 543, 528, 0, 0], false),\n ([0, 550, 0, 0, 0, 0, 544, 529, 0, 0], false),\n ([553, 0, 0, 0, 549, 0, 545, 530, 0, 0], false),\n ([0, 0, 0, 0, 550, 0, 546, 531, 0, 0], false),\n ([555, 0, 0, 0, 0, 0, 549, 534, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 550, 535, 0, 0], false),\n ([0, 555, 0, 0, 0, 0, 551, 536, 0, 0], false),\n ([558, 0, 0, 0, 554, 0, 552, 537, 0, 0], false),\n ([0, 0, 0, 0, 555, 0, 553, 538, 0, 0], false),\n ([566, 564, 0, 0, 560, 0, 0, 0, 518, 0], false),\n ([563, 561, 0, 0, 0, 0, 0, 0, 519, 0], false),\n ([562, 0, 0, 0, 0, 0, 0, 0, 520, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 521, 0], false),\n ([0, 562, 0, 0, 0, 0, 0, 0, 522, 0], false),\n ([565, 0, 0, 0, 561, 0, 0, 0, 523, 0], false),\n ([0, 0, 0, 0, 562, 0, 0, 0, 524, 0], false),\n ([0, 565, 0, 0, 563, 0, 0, 0, 525, 0], false),\n ([574, 572, 770, 768, 568, 737, 0, 559, 540, 0], false),\n ([571, 569, 767, 765, 761, 750, 0, 560, 541, 0], false),\n ([570, 0, 0, 0, 0, 0, 0, 561, 542, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 562, 543, 0], false),\n ([0, 570, 0, 0, 0, 0, 0, 563, 544, 0], false),\n ([573, 0, 0, 0, 569, 0, 0, 564, 545, 0], false),\n ([0, 0, 0, 0, 570, 0, 0, 565, 546, 0], false),\n ([0, 573, 0, 0, 571, 0, 0, 566, 547, 0], false),\n ([578, 576, 0, 0, 0, 0, 0, 0, 560, 0], false),\n ([577, 0, 0, 0, 0, 0, 0, 0, 561, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 562, 0], false),\n ([0, 577, 0, 0, 0, 0, 0, 0, 563, 0], false),\n ([0, 0, 0, 0, 577, 0, 0, 0, 565, 0], false),\n ([0, 579, 0, 0, 578, 0, 0, 0, 566, 0], false),\n ([584, 582, 849, 847, 843, 833, 0, 575, 568, 0], false),\n ([583, 0, 0, 0, 0, 0, 0, 576, 569, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 577, 570, 0], false),\n ([0, 583, 0, 0, 0, 0, 0, 578, 571, 0], false),\n ([0, 0, 0, 0, 583, 0, 0, 579, 573, 0], false),\n ([0, 585, 0, 0, 584, 0, 0, 580, 574, 0], false),\n ([0, 621, 615, 606, 588, 0, 0, 0, 0, 0], false),\n ([0, 604, 598, 589, 0, 0, 0, 0, 0, 0], false),\n ([0, 596, 590, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 594, 591, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 592, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 593, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 595, 592, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 593, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 597, 594, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 595, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 602, 599, 590, 0, 0, 0, 0, 0, 0], false),\n ([0, 600, 0, 591, 0, 0, 0, 0, 0, 0], false),\n ([0, 601, 0, 592, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 593, 0, 0, 0, 0, 0, 0], false),\n ([0, 603, 600, 594, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 601, 595, 0, 0, 0, 0, 0, 0], false),\n ([0, 605, 602, 596, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 603, 597, 0, 0, 0, 0, 0, 0], false),\n ([0, 613, 607, 0, 589, 0, 0, 0, 0, 0], false),\n ([0, 611, 608, 0, 590, 0, 0, 0, 0, 0], false),\n ([0, 609, 0, 0, 591, 0, 0, 0, 0, 0], false),\n ([0, 610, 0, 0, 592, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 593, 0, 0, 0, 0, 0], false),\n ([0, 612, 609, 0, 594, 0, 0, 0, 0, 0], false),\n ([0, 0, 610, 0, 595, 0, 0, 0, 0, 0], false),\n ([0, 614, 611, 0, 596, 0, 0, 0, 0, 0], false),\n ([0, 0, 612, 0, 597, 0, 0, 0, 0, 0], false),\n ([0, 619, 616, 607, 598, 0, 0, 0, 0, 0], false),\n ([0, 617, 0, 608, 599, 0, 0, 0, 0, 0], false),\n ([0, 618, 0, 609, 600, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 610, 601, 0, 0, 0, 0, 0], false),\n ([0, 620, 617, 611, 602, 0, 0, 0, 0, 0], false),\n ([0, 0, 618, 612, 603, 0, 0, 0, 0, 0], false),\n ([0, 622, 619, 613, 604, 0, 0, 0, 0, 0], false),\n ([0, 0, 620, 614, 605, 0, 0, 0, 0, 0], false),\n ([0, 630, 624, 0, 0, 0, 0, 589, 0, 0], false),\n ([0, 628, 625, 0, 0, 0, 0, 590, 0, 0], false),\n ([0, 626, 0, 0, 0, 0, 0, 591, 0, 0], false),\n ([0, 627, 0, 0, 0, 0, 0, 592, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 593, 0, 0], false),\n ([0, 629, 626, 0, 0, 0, 0, 594, 0, 0], false),\n ([0, 0, 627, 0, 0, 0, 0, 595, 0, 0], false),\n ([0, 631, 628, 0, 0, 0, 0, 596, 0, 0], false),\n ([0, 0, 629, 0, 0, 0, 0, 597, 0, 0], false),\n ([0, 636, 633, 624, 0, 0, 0, 598, 0, 0], false),\n ([0, 634, 0, 625, 0, 0, 0, 599, 0, 0], false),\n ([0, 635, 0, 626, 0, 0, 0, 600, 0, 0], false),\n ([0, 0, 0, 627, 0, 0, 0, 601, 0, 0], false),\n ([0, 637, 634, 628, 0, 0, 0, 602, 0, 0], false),\n ([0, 0, 635, 629, 0, 0, 0, 603, 0, 0], false),\n ([0, 0, 637, 631, 0, 0, 0, 605, 0, 0], false),\n ([0, 640, 0, 0, 625, 0, 0, 608, 0, 0], false),\n ([0, 641, 0, 0, 626, 0, 0, 609, 0, 0], false),\n ([0, 0, 0, 0, 627, 0, 0, 610, 0, 0], false),\n ([1119, 643, 640, 0, 628, 1109, 1098, 611, 0, 923], false),\n ([0, 0, 641, 0, 629, 0, 0, 612, 0, 0], false),\n ([1121, 645, 642, 0, 630, 1112, 1101, 613, 0, 926], false),\n ([0, 0, 643, 0, 631, 0, 0, 614, 0, 0], false),\n ([0, 647, 0, 639, 633, 0, 0, 616, 0, 0], false),\n ([0, 648, 0, 640, 634, 0, 0, 617, 0, 0], false),\n ([0, 0, 0, 641, 635, 0, 0, 618, 0, 0], false),\n ([1123, 650, 647, 642, 636, 1116, 1104, 619, 0, 930], false),\n ([0, 0, 648, 643, 637, 0, 0, 620, 0, 0], false),\n ([0, 0, 650, 645, 638, 0, 0, 622, 0, 0], false),\n ([0, 656, 653, 0, 821, 816, 797, 624, 0, 0], false),\n ([0, 654, 0, 0, 0, 0, 0, 625, 0, 0], false),\n ([0, 655, 0, 0, 0, 0, 0, 626, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 627, 0, 0], false),\n ([0, 657, 654, 0, 0, 0, 0, 628, 0, 0], false),\n ([0, 0, 655, 0, 0, 0, 0, 629, 0, 0], false),\n ([0, 0, 657, 0, 0, 0, 0, 631, 0, 0], false),\n ([0, 660, 0, 654, 0, 0, 0, 634, 0, 0], false),\n ([0, 0, 0, 655, 0, 0, 0, 635, 0, 0], false),\n ([0, 662, 659, 656, 0, 0, 0, 636, 0, 0], false),\n ([0, 0, 660, 657, 0, 0, 0, 637, 0, 0], false),\n ([0, 0, 662, 658, 0, 0, 0, 638, 0, 0], false),\n ([0, 665, 0, 0, 653, 0, 0, 639, 0, 0], false),\n ([0, 666, 0, 0, 654, 0, 0, 640, 0, 0], false),\n ([0, 0, 0, 0, 655, 0, 0, 641, 0, 0], false),\n ([1150, 668, 665, 0, 656, 1141, 1134, 642, 0, 986], false),\n ([0, 0, 666, 0, 657, 0, 0, 643, 0, 0], false),\n ([0, 0, 668, 0, 658, 0, 0, 645, 0, 0], false),\n ([0, 671, 0, 665, 659, 0, 0, 647, 0, 0], false),\n ([0, 0, 0, 666, 660, 0, 0, 648, 0, 0], false),\n ([0, 0, 671, 668, 662, 0, 0, 650, 0, 0], false),\n ([0, 0, 672, 669, 663, 0, 0, 651, 0, 0], false),\n ([0, 690, 684, 675, 0, 0, 0, 0, 588, 0], false),\n ([0, 682, 676, 0, 0, 0, 0, 0, 589, 0], false),\n ([0, 680, 677, 0, 0, 0, 0, 0, 590, 0], false),\n ([0, 678, 0, 0, 0, 0, 0, 0, 591, 0], false),\n ([0, 679, 0, 0, 0, 0, 0, 0, 592, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 593, 0], false),\n ([0, 681, 678, 0, 0, 0, 0, 0, 594, 0], false),\n ([0, 0, 679, 0, 0, 0, 0, 0, 595, 0], false),\n ([0, 683, 680, 0, 0, 0, 0, 0, 596, 0], false),\n ([0, 0, 681, 0, 0, 0, 0, 0, 597, 0], false),\n ([0, 688, 685, 676, 0, 0, 0, 0, 598, 0], false),\n ([0, 686, 0, 677, 0, 0, 0, 0, 599, 0], false),\n ([0, 687, 0, 678, 0, 0, 0, 0, 600, 0], false),\n ([0, 0, 0, 679, 0, 0, 0, 0, 601, 0], false),\n ([0, 689, 686, 680, 0, 0, 0, 0, 602, 0], false),\n ([0, 0, 687, 681, 0, 0, 0, 0, 603, 0], false),\n ([0, 691, 688, 682, 0, 0, 0, 0, 604, 0], false),\n ([0, 0, 689, 683, 0, 0, 0, 0, 605, 0], false),\n ([0, 699, 693, 0, 675, 0, 0, 0, 606, 0], false),\n ([0, 697, 694, 0, 676, 0, 0, 0, 607, 0], false),\n ([0, 695, 0, 0, 677, 0, 0, 0, 608, 0], false),\n ([0, 696, 0, 0, 678, 0, 0, 0, 609, 0], false),\n ([0, 0, 0, 0, 679, 0, 0, 0, 610, 0], false),\n ([0, 698, 695, 0, 680, 0, 0, 0, 611, 0], false),\n ([0, 0, 696, 0, 681, 0, 0, 0, 612, 0], false),\n ([0, 700, 697, 0, 682, 0, 0, 0, 613, 0], false),\n ([0, 0, 698, 0, 683, 0, 0, 0, 614, 0], false),\n ([0, 702, 0, 694, 685, 0, 0, 0, 616, 0], false),\n ([0, 703, 0, 695, 686, 0, 0, 0, 617, 0], false),\n ([0, 0, 0, 696, 687, 0, 0, 0, 618, 0], false),\n ([0, 711, 705, 0, 0, 0, 0, 675, 623, 0], false),\n ([0, 709, 706, 0, 0, 0, 0, 676, 624, 0], false),\n ([0, 707, 0, 0, 0, 0, 0, 677, 625, 0], false),\n ([0, 708, 0, 0, 0, 0, 0, 678, 626, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 679, 627, 0], false),\n ([0, 710, 707, 0, 0, 0, 0, 680, 628, 0], false),\n ([0, 0, 708, 0, 0, 0, 0, 681, 629, 0], false),\n ([0, 712, 709, 0, 0, 0, 0, 682, 630, 0], false),\n ([0, 0, 710, 0, 0, 0, 0, 683, 631, 0], false),\n ([0, 717, 714, 705, 0, 0, 0, 684, 632, 0], false),\n ([0, 715, 0, 706, 0, 0, 0, 685, 633, 0], false),\n ([0, 716, 0, 707, 0, 0, 0, 686, 634, 0], false),\n ([0, 0, 0, 708, 0, 0, 0, 687, 635, 0], false),\n ([0, 718, 715, 709, 0, 0, 0, 688, 636, 0], false),\n ([0, 0, 716, 710, 0, 0, 0, 689, 637, 0], false),\n ([0, 0, 718, 712, 0, 0, 0, 691, 638, 0], false),\n ([0, 721, 0, 0, 706, 0, 0, 694, 639, 0], false),\n ([0, 722, 0, 0, 707, 0, 0, 695, 640, 0], false),\n ([0, 0, 0, 0, 708, 0, 0, 696, 641, 0], false),\n ([0, 0, 0, 722, 716, 0, 0, 703, 648, 0], false),\n ([0, 725, 0, 0, 0, 0, 0, 706, 653, 0], false),\n ([0, 726, 0, 0, 0, 0, 0, 707, 654, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 708, 655, 0], false),\n ([0, 728, 725, 0, 0, 0, 0, 709, 656, 0], false),\n ([0, 0, 726, 0, 0, 0, 0, 710, 657, 0], false),\n ([0, 0, 728, 0, 0, 0, 0, 712, 658, 0], false),\n ([0, 0, 0, 726, 0, 0, 0, 716, 660, 0], false),\n ([0, 0, 730, 728, 0, 0, 0, 718, 662, 0], false),\n ([0, 0, 731, 729, 0, 0, 0, 719, 663, 0], false),\n ([0, 734, 0, 0, 724, 0, 0, 720, 664, 0], false),\n ([0, 735, 0, 0, 725, 0, 0, 721, 665, 0], false),\n ([0, 0, 0, 0, 726, 0, 0, 722, 666, 0], false),\n ([0, 0, 0, 735, 730, 0, 0, 723, 671, 0], false),\n ([0, 0, 760, 758, 750, 738, 0, 0, 0, 0], false),\n ([0, 0, 749, 747, 739, 0, 0, 0, 0, 0], false),\n ([0, 0, 746, 744, 740, 0, 0, 0, 0, 0], false),\n ([0, 0, 743, 741, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 742, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 0, 0, 742, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 745, 0, 741, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 742, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 745, 743, 0, 0, 0, 0, 0], false),\n ([0, 0, 748, 0, 744, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 745, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 748, 746, 0, 0, 0, 0, 0], false),\n ([0, 0, 757, 755, 751, 739, 0, 0, 0, 0], false),\n ([0, 0, 754, 752, 0, 740, 0, 0, 0, 0], false),\n ([0, 0, 753, 0, 0, 741, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 742, 0, 0, 0, 0], false),\n ([0, 0, 0, 753, 0, 743, 0, 0, 0, 0], false),\n ([0, 0, 756, 0, 752, 744, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 753, 745, 0, 0, 0, 0], false),\n ([0, 0, 0, 756, 754, 746, 0, 0, 0, 0], false),\n ([0, 0, 759, 0, 755, 747, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 756, 748, 0, 0, 0, 0], false),\n ([0, 0, 0, 759, 757, 749, 0, 0, 0, 0], false),\n ([0, 0, 764, 762, 0, 751, 0, 0, 0, 0], false),\n ([0, 0, 763, 0, 0, 752, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 753, 0, 0, 0, 0], false),\n ([0, 0, 0, 763, 0, 754, 0, 0, 0, 0], false),\n ([0, 0, 766, 0, 762, 755, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 763, 756, 0, 0, 0, 0], false),\n ([0, 0, 0, 766, 764, 757, 0, 0, 0, 0], false),\n ([0, 0, 769, 0, 765, 758, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 766, 759, 0, 0, 0, 0], false),\n ([0, 0, 0, 769, 767, 760, 0, 0, 0, 0], false),\n ([0, 0, 782, 780, 772, 0, 738, 0, 0, 0], false),\n ([0, 0, 779, 777, 773, 0, 739, 0, 0, 0], false),\n ([0, 0, 776, 774, 0, 0, 740, 0, 0, 0], false),\n ([0, 0, 775, 0, 0, 0, 741, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 742, 0, 0, 0], false),\n ([0, 0, 0, 775, 0, 0, 743, 0, 0, 0], false),\n ([0, 0, 778, 0, 774, 0, 744, 0, 0, 0], false),\n ([0, 0, 0, 0, 775, 0, 745, 0, 0, 0], false),\n ([0, 0, 0, 778, 776, 0, 746, 0, 0, 0], false),\n ([0, 0, 781, 0, 777, 0, 747, 0, 0, 0], false),\n ([0, 0, 0, 0, 778, 0, 748, 0, 0, 0], false),\n ([0, 0, 0, 781, 779, 0, 749, 0, 0, 0], false),\n ([0, 0, 786, 784, 0, 773, 751, 0, 0, 0], false),\n ([0, 0, 785, 0, 0, 774, 752, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 775, 753, 0, 0, 0], false),\n ([0, 0, 0, 785, 0, 776, 754, 0, 0, 0], false),\n ([0, 0, 788, 0, 784, 777, 755, 0, 0, 0], false),\n ([0, 0, 0, 0, 785, 778, 756, 0, 0, 0], false),\n ([0, 0, 0, 788, 786, 779, 757, 0, 0, 0], false),\n ([1130, 1128, 791, 0, 787, 780, 758, 1086, 0, 938], false),\n ([1127, 1125, 0, 0, 788, 781, 759, 1087, 0, 939], false),\n ([1133, 1131, 0, 791, 789, 782, 760, 1094, 0, 946], false),\n ([0, 0, 796, 794, 0, 783, 761, 0, 0, 0], false),\n ([0, 0, 795, 0, 0, 784, 762, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 785, 763, 0, 0, 0], false),\n ([0, 0, 0, 795, 0, 786, 764, 0, 0, 0], false),\n ([0, 0, 0, 0, 795, 788, 766, 0, 0, 0], false),\n ([0, 0, 0, 797, 796, 789, 767, 0, 0, 0], false),\n ([0, 0, 810, 808, 800, 0, 771, 0, 0, 0], false),\n ([0, 0, 807, 805, 801, 0, 772, 0, 0, 0], false),\n ([0, 0, 804, 802, 0, 0, 773, 0, 0, 0], false),\n ([0, 0, 803, 0, 0, 0, 774, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 775, 0, 0, 0], false),\n ([0, 0, 0, 803, 0, 0, 776, 0, 0, 0], false),\n ([0, 0, 806, 0, 802, 0, 777, 0, 0, 0], false),\n ([0, 0, 0, 0, 803, 0, 778, 0, 0, 0], false),\n ([0, 0, 0, 806, 804, 0, 779, 0, 0, 0], false),\n ([0, 0, 809, 0, 805, 0, 780, 0, 0, 0], false),\n ([0, 0, 0, 0, 806, 0, 781, 0, 0, 0], false),\n ([0, 0, 0, 809, 807, 0, 782, 0, 0, 0], false),\n ([0, 0, 814, 812, 0, 801, 783, 0, 0, 0], false),\n ([0, 0, 813, 0, 0, 802, 784, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 803, 785, 0, 0, 0], false),\n ([0, 0, 0, 813, 0, 804, 786, 0, 0, 0], false),\n ([0, 0, 816, 0, 812, 805, 787, 0, 0, 0], false),\n ([0, 0, 0, 0, 813, 806, 788, 0, 0, 0], false),\n ([1146, 1144, 818, 0, 815, 808, 790, 1107, 0, 969], false),\n ([1143, 1141, 0, 0, 816, 809, 791, 1108, 0, 970], false),\n ([0, 0, 822, 820, 0, 811, 793, 0, 0, 0], false),\n ([0, 0, 821, 0, 0, 812, 794, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 813, 795, 0, 0, 0], false),\n ([0, 0, 0, 821, 0, 814, 796, 0, 0, 0], false),\n ([0, 0, 830, 828, 824, 0, 0, 0, 739, 0], false),\n ([0, 0, 827, 825, 0, 0, 0, 0, 740, 0], false),\n ([0, 0, 826, 0, 0, 0, 0, 0, 741, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 742, 0], false),\n ([0, 0, 0, 826, 0, 0, 0, 0, 743, 0], false),\n ([0, 0, 829, 0, 825, 0, 0, 0, 744, 0], false),\n ([0, 0, 0, 0, 826, 0, 0, 0, 745, 0], false),\n ([0, 0, 0, 829, 827, 0, 0, 0, 746, 0], false),\n ([0, 0, 0, 0, 829, 0, 0, 0, 748, 0], false),\n ([0, 0, 0, 831, 830, 0, 0, 0, 749, 0], false),\n ([0, 0, 840, 838, 834, 823, 0, 0, 750, 0], false),\n ([0, 0, 837, 835, 0, 824, 0, 0, 751, 0], false),\n ([0, 0, 836, 0, 0, 825, 0, 0, 752, 0], false),\n ([0, 0, 0, 0, 0, 826, 0, 0, 753, 0], false),\n ([0, 0, 0, 836, 0, 827, 0, 0, 754, 0], false),\n ([0, 0, 839, 0, 835, 828, 0, 0, 755, 0], false),\n ([0, 0, 0, 0, 836, 829, 0, 0, 756, 0], false),\n ([0, 0, 0, 839, 837, 830, 0, 0, 757, 0], false),\n ([0, 0, 0, 0, 839, 831, 0, 0, 759, 0], false),\n ([0, 0, 0, 841, 840, 832, 0, 0, 760, 0], false),\n ([0, 0, 846, 844, 0, 834, 0, 0, 761, 0], false),\n ([0, 0, 845, 0, 0, 835, 0, 0, 762, 0], false),\n ([0, 0, 0, 0, 0, 836, 0, 0, 763, 0], false),\n ([0, 0, 0, 845, 0, 837, 0, 0, 764, 0], false),\n ([0, 0, 848, 0, 844, 838, 0, 0, 765, 0], false),\n ([0, 0, 0, 0, 845, 839, 0, 0, 766, 0], false),\n ([0, 0, 0, 848, 846, 840, 0, 0, 767, 0], false),\n ([0, 0, 0, 0, 848, 841, 0, 0, 769, 0], false),\n ([0, 0, 858, 856, 852, 0, 823, 0, 772, 0], false),\n ([0, 0, 855, 853, 0, 0, 824, 0, 773, 0], false),\n ([0, 0, 854, 0, 0, 0, 825, 0, 774, 0], false),\n ([0, 0, 0, 0, 0, 0, 826, 0, 775, 0], false),\n ([0, 0, 0, 854, 0, 0, 827, 0, 776, 0], false),\n ([0, 0, 857, 0, 853, 0, 828, 0, 777, 0], false),\n ([0, 0, 0, 0, 854, 0, 829, 0, 778, 0], false),\n ([0, 0, 0, 857, 855, 0, 830, 0, 779, 0], false),\n ([0, 0, 0, 0, 857, 0, 831, 0, 781, 0], false),\n ([0, 0, 0, 859, 858, 0, 832, 0, 782, 0], false),\n ([0, 0, 864, 862, 0, 852, 834, 0, 783, 0], false),\n ([0, 0, 863, 0, 0, 853, 835, 0, 784, 0], false),\n ([0, 0, 0, 0, 0, 854, 836, 0, 785, 0], false),\n ([0, 0, 0, 863, 0, 855, 837, 0, 786, 0], false),\n ([0, 0, 866, 0, 862, 856, 838, 0, 787, 0], false),\n ([0, 0, 0, 0, 863, 857, 839, 0, 788, 0], false),\n ([0, 0, 0, 866, 864, 858, 840, 0, 789, 0], false),\n ([1184, 1182, 0, 0, 866, 859, 841, 1155, 791, 1046], false),\n ([0, 0, 870, 0, 0, 862, 844, 0, 794, 0], false),\n ([0, 0, 0, 0, 0, 863, 845, 0, 795, 0], false),\n ([0, 0, 0, 0, 870, 866, 848, 0, 797, 0], false),\n ([935, 933, 929, 921, 0, 905, 873, 0, 0, 0], false),\n ([904, 902, 898, 890, 0, 874, 0, 0, 0, 0], false),\n ([889, 887, 883, 875, 0, 0, 0, 0, 0, 0], false),\n ([882, 880, 876, 0, 0, 0, 0, 0, 0, 0], false),\n ([879, 877, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([878, 0, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], true),\n ([0, 878, 0, 0, 0, 0, 0, 0, 0, 0], false),\n ([881, 0, 877, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 878, 0, 0, 0, 0, 0, 0, 0], false),\n ([0, 881, 879, 0, 0, 0, 0, 0, 0, 0], false),\n ([886, 884, 0, 876, 0, 0, 0, 0, 0, 0], false),\n ([885, 0, 0, 877, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 0, 878, 0, 0, 0, 0, 0, 0], false),\n ([0, 885, 0, 879, 0, 0, 0, 0, 0, 0], false),\n ([888, 0, 884, 880, 0, 0, 0, 0, 0, 0], false),\n ([0, 0, 885, 881, 0, 0, 0, 0, 0, 0], false),\n ([0, 888, 886, 882, 0, 0, 0, 0, 0, 0], false),\n ([897, 895, 891, 0, 0, 875, 0, 0, 0, 0], false),\n ([894, 892, 0, 0, 0, 876, 0, 0, 0, 0], false),\n ([893, 0, 0, 0, 0, 877, 0, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 878, 0, 0, 0, 0], false),\n ([0, 893, 0, 0, 0, 879, 0, 0, 0, 0], false),\n ([896, 0, 892, 0, 0, 880, 0, 0, 0, 0], false),\n ([0, 0, 893, 0, 0, 881, 0, 0, 0, 0], false),\n ([0, 896, 894, 0, 0, 882, 0, 0, 0, 0], false),\n ([901, 899, 0, 891, 0, 883, 0, 0, 0, 0], false),\n ([900, 0, 0, 892, 0, 884, 0, 0, 0, 0], false),\n ([0, 0, 0, 893, 0, 885, 0, 0, 0, 0], false),\n ([0, 900, 0, 894, 0, 886, 0, 0, 0, 0], false),\n ([903, 0, 899, 895, 0, 887, 0, 0, 0, 0], false),\n ([0, 0, 900, 896, 0, 888, 0, 0, 0, 0], false),\n ([0, 903, 901, 897, 0, 889, 0, 0, 0, 0], false),\n ([920, 918, 914, 906, 0, 0, 874, 0, 0, 0], false),\n ([913, 911, 907, 0, 0, 0, 875, 0, 0, 0], false),\n ([910, 908, 0, 0, 0, 0, 876, 0, 0, 0], false),\n ([909, 0, 0, 0, 0, 0, 877, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 878, 0, 0, 0], false),\n ([0, 909, 0, 0, 0, 0, 879, 0, 0, 0], false),\n ([912, 0, 908, 0, 0, 0, 880, 0, 0, 0], false),\n ([0, 0, 909, 0, 0, 0, 881, 0, 0, 0], false),\n ([0, 912, 910, 0, 0, 0, 882, 0, 0, 0], false),\n ([917, 915, 0, 907, 0, 0, 883, 0, 0, 0], false),\n ([916, 0, 0, 908, 0, 0, 884, 0, 0, 0], false),\n ([0, 0, 0, 909, 0, 0, 885, 0, 0, 0], false),\n ([0, 916, 0, 910, 0, 0, 886, 0, 0, 0], false),\n ([919, 0, 915, 911, 0, 0, 887, 0, 0, 0], false),\n ([0, 0, 916, 912, 0, 0, 888, 0, 0, 0], false),\n ([0, 919, 917, 913, 0, 0, 889, 0, 0, 0], false),\n ([928, 926, 922, 0, 0, 906, 890, 0, 0, 0], false),\n ([925, 923, 0, 0, 0, 907, 891, 0, 0, 0], false),\n ([924, 0, 0, 0, 0, 908, 892, 0, 0, 0], false),\n ([0, 0, 0, 0, 0, 909, 893, 0, 0, 0], false),\n ([0, 924, 0, 0, 0, 910, 894, 0, 0, 0], false),\n ([927, 0, 923, 0, 0, 911, 895, 0, 0, 0], false),\n ([0, 0, 924, 0, 0, 912, 896, 0, 0, 0], false),\n ([0, 927, 925, 0, 0, 913, 897, 0, 0, 0], false),\n ([932, 930, 0, 922, 0, 914, 898, 0, 0, 0], false),\n ([931, 0, 0, 923, 0, 915, 899, 0, 0, 0], false),\n ([0, 0, 0, 924, 0, 916, 900, 0, 0, 0], false),\n ([0, 931, 0, 925, 0, 917, 901, 0, 0, 0], false),\n ([934, 0, 930, 926, 0, 918, 902, 0, 0, 0], false),\n ([0, 0, 931, 927, 0, 919, 903, 0, 0, 0], false),\n ([0, 934, 932, 928, 0, 920, 904, 0, 0, 0], false),\n ([967, 965, 961, 953, 0, 937, 0, 873, 0, 0], false),\n ([952, 950, 946, 938, 0, 0, 0, 874, 0, 0], false),\n ([945, 943, 939, 0, 0, 0, 0, 875, 0, 0], false),\n ([942, 940, 0, 0, 0, 0, 0, 876, 0, 0], false),\n ([941, 0, 0, 0, 0, 0, 0, 877, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 878, 0, 0], false),\n ([0, 941, 0, 0, 0, 0, 0, 879, 0, 0], false),\n ([944, 0, 940, 0, 0, 0, 0, 880, 0, 0], false),\n ([0, 0, 941, 0, 0, 0, 0, 881, 0, 0], false),\n ([0, 944, 942, 0, 0, 0, 0, 882, 0, 0], false),\n ([949, 947, 0, 939, 0, 0, 0, 883, 0, 0], false),\n ([948, 0, 0, 940, 0, 0, 0, 884, 0, 0], false),\n ([0, 0, 0, 941, 0, 0, 0, 885, 0, 0], false),\n ([0, 948, 0, 942, 0, 0, 0, 886, 0, 0], false),\n ([951, 0, 947, 943, 0, 0, 0, 887, 0, 0], false),\n ([0, 0, 948, 944, 0, 0, 0, 888, 0, 0], false),\n ([0, 951, 949, 945, 0, 0, 0, 889, 0, 0], false),\n ([960, 958, 954, 0, 0, 938, 0, 890, 0, 0], false),\n ([957, 955, 0, 0, 0, 939, 0, 891, 0, 0], false),\n ([956, 0, 0, 0, 0, 940, 0, 892, 0, 0], false),\n ([0, 0, 0, 0, 0, 941, 0, 893, 0, 0], false),\n ([0, 956, 0, 0, 0, 942, 0, 894, 0, 0], false),\n ([959, 0, 955, 0, 0, 943, 0, 895, 0, 0], false),\n ([0, 0, 956, 0, 0, 944, 0, 896, 0, 0], false),\n ([0, 959, 957, 0, 0, 945, 0, 897, 0, 0], false),\n ([964, 962, 0, 954, 0, 946, 0, 898, 0, 0], false),\n ([963, 0, 0, 955, 0, 947, 0, 899, 0, 0], false),\n ([0, 0, 0, 956, 0, 948, 0, 900, 0, 0], false),\n ([0, 963, 0, 957, 0, 949, 0, 901, 0, 0], false),\n ([966, 0, 962, 958, 0, 950, 0, 902, 0, 0], false),\n ([0, 0, 963, 959, 0, 951, 0, 903, 0, 0], false),\n ([0, 966, 964, 960, 0, 952, 0, 904, 0, 0], false),\n ([983, 981, 977, 969, 0, 0, 937, 905, 0, 0], false),\n ([976, 974, 970, 0, 0, 0, 938, 906, 0, 0], false),\n ([973, 971, 0, 0, 0, 0, 939, 907, 0, 0], false),\n ([972, 0, 0, 0, 0, 0, 940, 908, 0, 0], false),\n ([0, 0, 0, 0, 0, 0, 941, 909, 0, 0], false),\n ([0, 972, 0, 0, 0, 0, 942, 910, 0, 0], false),\n ([975, 0, 971, 0, 0, 0, 943, 911, 0, 0], false),\n ([0, 0, 972, 0, 0, 0, 944, 912, 0, 0], false),\n ([0, 975, 973, 0, 0, 0, 945, 913, 0, 0], false),\n ([980, 978, 0, 970, 0, 0, 946, 914, 0, 0], false),\n ([979, 0, 0, 971, 0, 0, 947, 915, 0, 0], false),\n ([0, 0, 0, 972, 0, 0, 948, 916, 0, 0], false),\n ([0, 979, 0, 973, 0, 0, 949, 917, 0, 0], false),\n ([982, 0, 978, 974, 0, 0, 950, 918, 0, 0], false),\n ([0, 0, 979, 975, 0, 0, 951, 919, 0, 0], false),\n ([0, 982, 980, 976, 0, 0, 952, 920, 0, 0], false),\n ([991, 989, 985, 0, 0, 969, 953, 921, 0, 0], false),\n ([988, 986, 0, 0, 0, 970, 954, 922, 0, 0], false),\n ([987, 0, 0, 0, 0, 971, 955, 923, 0, 0], false),\n ([0, 0, 0, 0, 0, 972, 956, 924, 0, 0], false),\n ([0, 987, 0, 0, 0, 973, 957, 925, 0, 0], false),\n ([990, 0, 986, 0, 0, 974, 958, 926, 0, 0], false),\n ([0, 0, 987, 0, 0, 975, 959, 927, 0, 0], false),\n ([0, 990, 988, 0, 0, 976, 960, 928, 0, 0], false),\n ([0, 0, 0, 987, 0, 979, 963, 931, 0, 0], false),\n ([0, 992, 0, 988, 0, 980, 964, 932, 0, 0], false),\n ([0, 0, 992, 990, 0, 982, 966, 934, 0, 0], false),\n ([0, 994, 993, 991, 0, 983, 967, 935, 0, 0], false),\n ([1027, 1025, 1021, 1013, 0, 997, 0, 0, 873, 0], false),\n ([1012, 1010, 1006, 998, 0, 0, 0, 0, 874, 0], false),\n ([1005, 1003, 999, 0, 0, 0, 0, 0, 875, 0], false),\n ([1002, 1000, 0, 0, 0, 0, 0, 0, 876, 0], false),\n ([1001, 0, 0, 0, 0, 0, 0, 0, 877, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 878, 0], false),\n ([0, 1001, 0, 0, 0, 0, 0, 0, 879, 0], false),\n ([1004, 0, 1000, 0, 0, 0, 0, 0, 880, 0], false),\n ([0, 0, 1001, 0, 0, 0, 0, 0, 881, 0], false),\n ([0, 1004, 1002, 0, 0, 0, 0, 0, 882, 0], false),\n ([1009, 1007, 0, 999, 0, 0, 0, 0, 883, 0], false),\n ([1008, 0, 0, 1000, 0, 0, 0, 0, 884, 0], false),\n ([0, 0, 0, 1001, 0, 0, 0, 0, 885, 0], false),\n ([0, 1008, 0, 1002, 0, 0, 0, 0, 886, 0], false),\n ([1011, 0, 1007, 1003, 0, 0, 0, 0, 887, 0], false),\n ([0, 0, 1008, 1004, 0, 0, 0, 0, 888, 0], false),\n ([0, 1011, 1009, 1005, 0, 0, 0, 0, 889, 0], false),\n ([1020, 1018, 1014, 0, 0, 998, 0, 0, 890, 0], false),\n ([1017, 1015, 0, 0, 0, 999, 0, 0, 891, 0], false),\n ([1016, 0, 0, 0, 0, 1000, 0, 0, 892, 0], false),\n ([0, 0, 0, 0, 0, 1001, 0, 0, 893, 0], false),\n ([0, 1016, 0, 0, 0, 1002, 0, 0, 894, 0], false),\n ([1019, 0, 1015, 0, 0, 1003, 0, 0, 895, 0], false),\n ([0, 0, 1016, 0, 0, 1004, 0, 0, 896, 0], false),\n ([0, 1019, 1017, 0, 0, 1005, 0, 0, 897, 0], false),\n ([1024, 1022, 0, 1014, 0, 1006, 0, 0, 898, 0], false),\n ([1023, 0, 0, 1015, 0, 1007, 0, 0, 899, 0], false),\n ([0, 0, 0, 1016, 0, 1008, 0, 0, 900, 0], false),\n ([0, 1023, 0, 1017, 0, 1009, 0, 0, 901, 0], false),\n ([1026, 0, 1022, 1018, 0, 1010, 0, 0, 902, 0], false),\n ([0, 0, 1023, 1019, 0, 1011, 0, 0, 903, 0], false),\n ([0, 1026, 1024, 1020, 0, 1012, 0, 0, 904, 0], false),\n ([1035, 1033, 1029, 0, 0, 0, 998, 0, 906, 0], false),\n ([1032, 1030, 0, 0, 0, 0, 999, 0, 907, 0], false),\n ([1031, 0, 0, 0, 0, 0, 1000, 0, 908, 0], false),\n ([0, 0, 0, 0, 0, 0, 1001, 0, 909, 0], false),\n ([0, 1031, 0, 0, 0, 0, 1002, 0, 910, 0], false),\n ([1034, 0, 1030, 0, 0, 0, 1003, 0, 911, 0], false),\n ([0, 0, 1031, 0, 0, 0, 1004, 0, 912, 0], false),\n ([0, 1034, 1032, 0, 0, 0, 1005, 0, 913, 0], false),\n ([1043, 1041, 1037, 0, 0, 1028, 1013, 0, 921, 0], false),\n ([1040, 1038, 0, 0, 0, 1029, 1014, 0, 922, 0], false),\n ([1039, 0, 0, 0, 0, 1030, 1015, 0, 923, 0], false),\n ([0, 0, 0, 0, 0, 1031, 1016, 0, 924, 0], false),\n ([0, 1039, 0, 0, 0, 1032, 1017, 0, 925, 0], false),\n ([1042, 0, 1038, 0, 0, 1033, 1018, 0, 926, 0], false),\n ([0, 0, 1039, 0, 0, 1034, 1019, 0, 927, 0], false),\n ([0, 1042, 1040, 0, 0, 1035, 1020, 0, 928, 0], false),\n ([1059, 1057, 1053, 1045, 0, 0, 0, 997, 937, 0], false),\n ([1052, 1050, 1046, 0, 0, 0, 0, 998, 938, 0], false),\n ([1049, 1047, 0, 0, 0, 0, 0, 999, 939, 0], false),\n ([1048, 0, 0, 0, 0, 0, 0, 1000, 940, 0], false),\n ([0, 0, 0, 0, 0, 0, 0, 1001, 941, 0], false),\n ([0, 1048, 0, 0, 0, 0, 0, 1002, 942, 0], false),\n ([1051, 0, 1047, 0, 0, 0, 0, 1003, 943, 0], false),\n ([0, 0, 1048, 0, 0, 0, 0, 1004, 944, 0], false),\n ([0, 1051, 1049, 0, 0, 0, 0, 1005, 945, 0], false),\n ([1056, 1054, 0, 1046, 0, 0, 0, 1006, 946, 0], false),\n ([1055, 0, 0, 1047, 0, 0, 0, 1007, 947, 0], false),\n ([0, 0, 0, 1048, 0, 0, 0, 1008, 948, 0], false),\n ([0, 1055, 0, 1049, 0, 0, 0, 1009, 949, 0], false),\n ([1058, 0, 1054, 1050, 0, 0, 0, 1010, 950, 0], false),\n ([0, 0, 1055, 1051, 0, 0, 0, 1011, 951, 0], false),\n ([0, 1058, 1056, 1052, 0, 0, 0, 1012, 952, 0], false),\n ([1067, 1065, 1061, 0, 0, 1045, 0, 1013, 953, 0], false),\n ([1064, 1062, 0, 0, 0, 1046, 0, 1014, 954, 0], false),\n ([1063, 0, 0, 0, 0, 1047, 0, 1015, 955, 0], false),\n ([0, 0, 0, 0, 0, 1048, 0, 1016, 956, 0], false),\n ([0, 1063, 0, 0, 0, 1049, 0, 1017, 957, 0], false),\n ([1066, 0, 1062, 0, 0, 1050, 0, 1018, 958, 0], false),\n ([0, 0, 1063, 0, 0, 1051, 0, 1019, 959, 0], false),\n ([0, 1066, 1064, 0, 0, 1052, 0, 1020, 960, 0], false),\n ([1071, 1069, 0, 1061, 0, 1053, 0, 1021, 961, 0], false),\n ([1070, 0, 0, 1062, 0, 1054, 0, 1022, 962, 0], false),\n ([0, 0, 0, 1063, 0, 1055, 0, 1023, 963, 0], false),\n ([0, 1070, 0, 1064, 0, 1056, 0, 1024, 964, 0], false),\n ([1073, 0, 1069, 1065, 0, 1057, 0, 1025, 965, 0], false),\n ([0, 0, 1070, 1066, 0, 1058, 0, 1026, 966, 0], false),\n ([1081, 1079, 1075, 0, 0, 0, 1045, 1028, 969, 0], false),\n ([1078, 1076, 0, 0, 0, 0, 1046, 1029, 970, 0], false),\n ([1077, 0, 0, 0, 0, 0, 1047, 1030, 971, 0], false),\n ([0, 0, 0, 0, 0, 0, 1048, 1031, 972, 0], false),\n ([0, 1077, 0, 0, 0, 0, 1049, 1032, 973, 0], false),\n ([1080, 0, 1076, 0, 0, 0, 1050, 1033, 974, 0], false),\n ([0, 0, 1077, 0, 0, 0, 1051, 1034, 975, 0], false),\n ([0, 1080, 1078, 0, 0, 0, 1052, 1035, 976, 0], false),\n ([1085, 1083, 0, 0, 0, 1075, 1061, 1037, 985, 0], false),\n ([1084, 0, 0, 0, 0, 1076, 1062, 1038, 986, 0], false),\n ([0, 0, 0, 0, 0, 1077, 1063, 1039, 987, 0], false),\n ([0, 1084, 0, 0, 0, 1078, 1064, 1040, 988, 0], false),\n ([1093, 1091, 1087, 0, 0, 0, 0, 0, 0, 875], false),\n ([1090, 1088, 0, 0, 0, 0, 0, 0, 0, 876], false),\n ([1089, 0, 0, 0, 0, 0, 0, 0, 0, 877], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 0, 878], false),\n ([0, 1089, 0, 0, 0, 0, 0, 0, 0, 879], false),\n ([1092, 0, 1088, 0, 0, 0, 0, 0, 0, 880], false),\n ([0, 0, 1089, 0, 0, 0, 0, 0, 0, 881], false),\n ([0, 1092, 1090, 0, 0, 0, 0, 0, 0, 882], false),\n ([1097, 1095, 0, 1087, 0, 0, 0, 0, 0, 883], false),\n ([1096, 0, 0, 1088, 0, 0, 0, 0, 0, 884], false),\n ([0, 0, 0, 1089, 0, 0, 0, 0, 0, 885], false),\n ([0, 1096, 0, 1090, 0, 0, 0, 0, 0, 886], false),\n ([1099, 0, 0, 0, 0, 1088, 0, 0, 0, 892], false),\n ([0, 0, 0, 0, 0, 1089, 0, 0, 0, 893], false),\n ([0, 1099, 0, 0, 0, 1090, 0, 0, 0, 894], false),\n ([1102, 0, 1098, 0, 0, 1091, 0, 0, 0, 895], false),\n ([0, 0, 1099, 0, 0, 1092, 0, 0, 0, 896], false),\n ([0, 1102, 1100, 0, 0, 1093, 0, 0, 0, 897], false),\n ([1105, 0, 0, 1098, 0, 1095, 0, 0, 0, 899], false),\n ([0, 0, 0, 1099, 0, 1096, 0, 0, 0, 900], false),\n ([0, 1105, 0, 1100, 0, 1097, 0, 0, 0, 901], false),\n ([1114, 1112, 1108, 0, 0, 0, 1086, 0, 0, 906], false),\n ([1111, 1109, 0, 0, 0, 0, 1087, 0, 0, 907], false),\n ([1110, 0, 0, 0, 0, 0, 1088, 0, 0, 908], false),\n ([0, 0, 0, 0, 0, 0, 1089, 0, 0, 909], false),\n ([0, 1110, 0, 0, 0, 0, 1090, 0, 0, 910], false),\n ([1113, 0, 1109, 0, 0, 0, 1091, 0, 0, 911], false),\n ([0, 0, 1110, 0, 0, 0, 1092, 0, 0, 912], false),\n ([0, 1113, 1111, 0, 0, 0, 1093, 0, 0, 913], false),\n ([1118, 1116, 0, 1108, 0, 0, 1094, 0, 0, 914], false),\n ([1117, 0, 0, 1109, 0, 0, 1095, 0, 0, 915], false),\n ([0, 0, 0, 1110, 0, 0, 1096, 0, 0, 916], false),\n ([0, 1117, 0, 1111, 0, 0, 1097, 0, 0, 917], false),\n ([0, 0, 0, 0, 0, 1110, 1099, 0, 0, 924], false),\n ([0, 1119, 0, 0, 0, 1111, 1100, 0, 0, 925], false),\n ([0, 0, 1119, 0, 0, 1113, 1102, 0, 0, 927], false),\n ([0, 1121, 1120, 0, 0, 1114, 1103, 0, 0, 928], false),\n ([0, 0, 0, 1119, 0, 1117, 1105, 0, 0, 931], false),\n ([0, 1123, 0, 1120, 0, 1118, 1106, 0, 0, 932], false),\n ([1126, 0, 0, 0, 0, 0, 0, 1088, 0, 940], false),\n ([0, 0, 0, 0, 0, 0, 0, 1089, 0, 941], false),\n ([0, 1126, 0, 0, 0, 0, 0, 1090, 0, 942], false),\n ([1129, 0, 1125, 0, 0, 0, 0, 1091, 0, 943], false),\n ([0, 0, 1126, 0, 0, 0, 0, 1092, 0, 944], false),\n ([0, 1129, 1127, 0, 0, 0, 0, 1093, 0, 945], false),\n ([1132, 0, 0, 1125, 0, 0, 0, 1095, 0, 947], false),\n ([0, 0, 0, 1126, 0, 0, 0, 1096, 0, 948], false),\n ([0, 1132, 0, 1127, 0, 0, 0, 1097, 0, 949], false),\n ([1135, 0, 0, 0, 0, 1125, 0, 1098, 0, 955], false),\n ([0, 0, 0, 0, 0, 1126, 0, 1099, 0, 956], false),\n ([0, 1135, 0, 0, 0, 1127, 0, 1100, 0, 957], false),\n ([0, 0, 1135, 0, 0, 1129, 0, 1102, 0, 959], false),\n ([1139, 0, 0, 1134, 0, 1131, 0, 1104, 0, 962], false),\n ([0, 0, 0, 1135, 0, 1132, 0, 1105, 0, 963], false),\n ([0, 1139, 0, 1136, 0, 1133, 0, 1106, 0, 964], false),\n ([1142, 0, 0, 0, 0, 0, 1125, 1109, 0, 971], false),\n ([0, 0, 0, 0, 0, 0, 1126, 1110, 0, 972], false),\n ([0, 1142, 0, 0, 0, 0, 1127, 1111, 0, 973], false),\n ([1145, 0, 1141, 0, 0, 0, 1128, 1112, 0, 974], false),\n ([0, 0, 1142, 0, 0, 0, 1129, 1113, 0, 975], false),\n ([0, 1145, 1143, 0, 0, 0, 1130, 1114, 0, 976], false),\n ([1148, 0, 0, 1141, 0, 0, 1131, 1116, 0, 978], false),\n ([0, 0, 0, 1142, 0, 0, 1132, 1117, 0, 979], false),\n ([0, 1148, 0, 1143, 0, 0, 1133, 1118, 0, 980], false),\n ([0, 0, 0, 0, 0, 1142, 1135, 1119, 0, 987], false),\n ([0, 1150, 0, 0, 0, 1143, 1136, 1120, 0, 988], false),\n ([0, 0, 1150, 0, 0, 1145, 1137, 1121, 0, 990], false),\n ([0, 0, 0, 1150, 0, 1148, 1139, 1123, 0, 992], false),\n ([1161, 1159, 1155, 0, 0, 0, 0, 0, 1086, 998], false),\n ([1158, 1156, 0, 0, 0, 0, 0, 0, 1087, 999], false),\n ([1157, 0, 0, 0, 0, 0, 0, 0, 1088, 1000], false),\n ([0, 0, 0, 0, 0, 0, 0, 0, 1089, 1001], false),\n ([0, 1157, 0, 0, 0, 0, 0, 0, 1090, 1002], false),\n ([1160, 0, 1156, 0, 0, 0, 0, 0, 1091, 1003], false),\n ([0, 0, 1157, 0, 0, 0, 0, 0, 1092, 1004], false),\n ([0, 1160, 1158, 0, 0, 0, 0, 0, 1093, 1005], false),\n ([1165, 1163, 0, 1155, 0, 0, 0, 0, 1094, 1006], false),\n ([1164, 0, 0, 1156, 0, 0, 0, 0, 1095, 1007], false),\n ([0, 0, 0, 1157, 0, 0, 0, 0, 1096, 1008], false),\n ([0, 1164, 0, 1158, 0, 0, 0, 0, 1097, 1009], false),\n ([1167, 0, 0, 0, 0, 1156, 0, 0, 1098, 1015], false),\n ([0, 0, 0, 0, 0, 1157, 0, 0, 1099, 1016], false),\n ([0, 1167, 0, 0, 0, 1158, 0, 0, 1100, 1017], false),\n ([1170, 0, 1166, 0, 0, 1159, 0, 0, 1101, 1018], false),\n ([0, 0, 1167, 0, 0, 1160, 0, 0, 1102, 1019], false),\n ([0, 1170, 1168, 0, 0, 1161, 0, 0, 1103, 1020], false),\n ([0, 0, 0, 1167, 0, 1164, 0, 0, 1105, 1023], false),\n ([0, 1172, 0, 1168, 0, 1165, 0, 0, 1106, 1024], false),\n ([1181, 1179, 1175, 0, 0, 0, 1154, 0, 1107, 1028], false),\n ([1178, 1176, 0, 0, 0, 0, 1155, 0, 1108, 1029], false),\n ([1177, 0, 0, 0, 0, 0, 1156, 0, 1109, 1030], false),\n ([0, 0, 0, 0, 0, 0, 1157, 0, 1110, 1031], false),\n ([0, 1177, 0, 0, 0, 0, 1158, 0, 1111, 1032], false),\n ([1180, 0, 1176, 0, 0, 0, 1159, 0, 1112, 1033], false),\n ([0, 0, 1177, 0, 0, 0, 1160, 0, 1113, 1034], false),\n ([0, 1180, 1178, 0, 0, 0, 1161, 0, 1114, 1035], false),\n ([1183, 0, 0, 0, 0, 0, 0, 1156, 1125, 1047], false),\n ([0, 0, 0, 0, 0, 0, 0, 1157, 1126, 1048], false),\n ([0, 1183, 0, 0, 0, 0, 0, 1158, 1127, 1049], false),\n ([1186, 0, 1182, 0, 0, 0, 0, 1159, 1128, 1050], false),\n ([0, 0, 1183, 0, 0, 0, 0, 1160, 1129, 1051], false),\n ([0, 1186, 1184, 0, 0, 0, 0, 1161, 1130, 1052], false),\n ([1189, 0, 0, 1182, 0, 0, 0, 1163, 1131, 1054], false),\n ([0, 0, 0, 1183, 0, 0, 0, 1164, 1132, 1055], false),\n ([0, 1189, 0, 1184, 0, 0, 0, 1165, 1133, 1056], false),\n ([1192, 0, 0, 0, 0, 1182, 0, 1166, 1134, 1062], false),\n ([0, 0, 0, 0, 0, 1183, 0, 1167, 1135, 1063], false),\n ([0, 1192, 0, 0, 0, 1184, 0, 1168, 1136, 1064], false),\n ([0, 0, 1192, 0, 0, 1186, 0, 1170, 1137, 1066], false),\n ([0, 0, 0, 1192, 0, 1189, 0, 1172, 1139, 1070], false),\n ([0, 1195, 0, 1193, 0, 1190, 0, 1173, 1140, 1071], false),\n ([1198, 0, 0, 0, 0, 0, 1182, 1176, 1141, 1076], false),\n ([0, 0, 0, 0, 0, 0, 1183, 1177, 1142, 1077], false),\n ([0, 1198, 0, 0, 0, 0, 1184, 1178, 1143, 1078], false),\n ([1201, 0, 1197, 0, 0, 0, 1185, 1179, 1144, 1079], false),\n ([0, 0, 1198, 0, 0, 0, 1186, 1180, 1145, 1080], false),\n ([0, 1201, 1199, 0, 0, 0, 1187, 1181, 1146, 1081], false),\n];\n```\n\nIf you scrolled all the way here, you might as well enjoy reading the program that generates the graph:\n\n```\nconst N_DIGITS: usize = 10;\n\nuse std::collections::HashMap;\n\nfn get_node_id(digits: &[usize], visited: &mut [bool], n_visited: usize) -> usize {\n if n_visited == 0 {\n usize::MAX\n } else {\n digits\n .iter()\n .zip(visited.iter())\n .fold(0, |id, (d, v)| if *v { id * 10 + *d } else { id })\n }\n}\n\nfn backtrack(\n digits: &[usize],\n visited: &mut [bool],\n depth: usize,\n graph: &mut HashMap<usize, (usize, [usize; N_DIGITS], bool)>,\n node_number: &mut usize,\n) {\n let curr_id = get_node_id(digits, visited, depth);\n if depth == digits.len() {\n graph.get_mut(&curr_id).unwrap().2 = true;\n } else {\n graph.entry(curr_id).or_insert_with(|| {\n let nn = *node_number;\n *node_number += 1;\n (nn, [0; N_DIGITS], false)\n });\n\n for i in 0..digits.len() {\n if !visited[i] {\n visited[i] = true;\n let next_id = get_node_id(digits, visited, depth + 1);\n let next_node_number = graph\n .entry(next_id)\n .or_insert_with(|| {\n let nn = *node_number;\n *node_number += 1;\n (nn, [0; N_DIGITS], false)\n })\n .0;\n graph.get_mut(&curr_id).unwrap().1[digits[i]] = next_node_number;\n backtrack(digits, visited, depth + 1, graph, node_number);\n visited[i] = false;\n }\n }\n }\n}\n\nfn get_digits(mut n: i32) -> Vec<usize> {\n if n == 0 {\n vec![0]\n } else {\n let mut rez = vec![];\n while n > 0 {\n rez.push((n % 10) as usize);\n n /= 10;\n }\n rez.sort_unstable_by(|d1, d2| d2.cmp(d1));\n rez\n }\n}\n\nfn insert(\n n: i32,\n graph: &mut HashMap<usize, (usize, [usize; N_DIGITS], bool)>,\n node_number: &mut usize,\n) {\n let digits = get_digits(n);\n let mut visited = vec![false; digits.len()];\n backtrack(&digits, &mut visited, 0, graph, node_number);\n}\n\nfn main() {\n let mut node_number = 0;\n let mut graph_map = HashMap::new();\n for shift in 0..30 {\n insert(1 << shift, &mut graph_map, &mut node_number);\n }\n let mut graph = graph_map.values().copied().collect::<Vec<_>>();\n graph.sort_unstable_by_key(|(node_number, _, _)| *node_number);\n let graph = graph\n .into_iter()\n .map(|(_, edges, leaf)| (edges, leaf))\n .collect::<Vec<_>>();\n println!("{:?}", graph);\n println!("{:?}", graph.len());\n}\n``` | 2 | 0 | ['Rust'] | 0 |
reordered-power-of-2 | C++ || Python || Simple Fastest Solution || with Explanation | c-python-simple-fastest-solution-with-ex-02a2 | Idea:\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the c | bvian | NORMAL | 2022-08-26T06:47:22.102142+00:00 | 2022-08-26T06:47:22.102203+00:00 | 47 | false | **Idea:**\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them both and the compare the result.\n\nIn that sense, the easiest solution here is to do exactly that: we can convert **N** to an array of its digits, sort it, then compare that result to the result of the same process on each power of **2**.\n\nSince the constraint upon **N** is **10e9**, we only need to check powers in the range **[0,29]**.\n\nTo make things easier to compare, we can always **join()** the resulting digit arrays into strings before comparison.\n\n**C++ Code:**\nThe best result for the code below is 0ms / 5.9MB (beats 100% / 83.90%).\n```\nclass Solution {\npublic:\n string convert(int n) {\n string s = to_string(n);\n sort(s.begin(), s.end());\n return s;\n }\n \n bool reorderedPowerOf2(int n) {\n string s = convert(n);\n for (int i = 0; i < 30; i++) {\n if (s == convert(1 << i)) return true;\n }\n return false;\n }\n};\n```\n\n**Python Code:**\nThe best result for the code below is 33ms / 14MB (beats 98.93% / 26.74%).\n```\nclass Solution:\n def reorderedPowerOf2(self, n: int) -> bool:\n def getConvert(n):\n return "".join(sorted([x for x in str(n)]))\n s = getConvert(n)\n for i in range(30):\n if s == getConvert(1<<i): return True\n return False\n``` | 2 | 0 | ['C', 'Sorting', 'Python'] | 0 |
reordered-power-of-2 | ✅ Q869.C++ || 100% time & space || fast & easy | q869c-100-time-space-fast-easy-by-jayden-dv2h | C++ Code:\n\n bool isEqual(int arr1[10], int arr2[10]) {\n for (int i = 0; i < 10; i++) if (arr1[i] != arr2[i]) return 0;\n return 1;\n }\n\ | JaydenCh-0v0 | NORMAL | 2022-08-26T06:38:26.503622+00:00 | 2022-08-26T06:53:03.430401+00:00 | 123 | false | C++ Code:\n```\n bool isEqual(int arr1[10], int arr2[10]) {\n for (int i = 0; i < 10; i++) if (arr1[i] != arr2[i]) return 0;\n return 1;\n }\n\n int countDigits(int num, int digits[10]) {\n int cnt = 0;\n while (num > 0) digits[num % 10]++, num /= 10, cnt++;\n return cnt;\n }\n\n bool reorderedPowerOf2(int num) {\n if (num > 0) {\n int numDigits[10] = { 0 }, numCnt = countDigits(num, numDigits);\n long po2 = 1; // po2: Power of 2\n while (1) {\n int po2Digits[10] = { 0 }, po2Cnt = countDigits(po2, po2Digits);\n po2 <<= 1; // same as (po2 = po2 * 2;)\n if (po2Cnt < numCnt) continue;\n if (po2Cnt > numCnt || po2 > INT_MAX) break;\n if (isEqual(numDigits, po2Digits)) return 1;\n }\n }\n return 0;\n }\n```\n**The complexity of this solution:**\n-\tTime: O( n^2 ) // depend on the size of num and po2\n-\tSpace: O( 1 ) // constant array size\n\nResult: \n\n**If you loved this solution please up vote, enjoy your coding \uD83D\uDE0A\uD83D\uDE0A** | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | 90% Tc and 78% SC python magic | 90-tc-and-78-sc-python-magic-by-nitanshr-y3aj | \ndef reorderedPowerOf2(self, n: int) -> bool:\n\tnum = set("".join(sorted(str(2**i))) for i in range(0, 32))\n\tn = \'\'.join(sorted(str(n)))\n\treturn n in nu | nitanshritulon | NORMAL | 2022-08-26T06:15:45.405046+00:00 | 2022-08-26T06:15:45.405089+00:00 | 101 | false | ```\ndef reorderedPowerOf2(self, n: int) -> bool:\n\tnum = set("".join(sorted(str(2**i))) for i in range(0, 32))\n\tn = \'\'.join(sorted(str(n)))\n\treturn n in num\n``` | 2 | 0 | ['Sorting', 'Python', 'Python3'] | 0 |
reordered-power-of-2 | C++ 100% Faster 0ms Solution by Hash | c-100-faster-0ms-solution-by-hash-by-nao-9i4v | Workaround\n\nAccording to the question, we need to reorder the target number n to indicate whether the number is power of 2. That is, the count of each digit i | naon | NORMAL | 2022-08-26T06:15:02.288574+00:00 | 2022-08-26T07:08:44.011284+00:00 | 99 | false | # **Workaround**\n\nAccording to the question, we need to reorder the target number `n` to indicate whether the number is power of 2. That is, the count of each digit in `n` must be same as the certain number which is power of 2. Therefore, we can use a custom hash function to count the digits:\n\n``` cpp\nint hashNumber(int n) {\n auto res = int(0); /// our result hash value.\n while (n != 0) { /// loop the number by taking its last digit until it becomes zero. \n res += int(pow(10, n % 10)); /// take digit and add res by 10 ^ n.\n n /= 10; /// iterate to next digit.\n }\n return res;\n}\n```\n\nNote for the argument `n` of function. We have constraints from the question `1 <= n <= 10^9` hence there is impossible to have a number with the count of certain digit more than `9`. We can add our result `res` by `pow(10, n%10*m)` if the count of certain digit can be increased to `m`-digits.\n\n---\n# **Constant Variable**\n\nWhen it comes to the hash values of the power of 2, it always calculate the same hash value of `1`, `2`, `4`, `8` ... etc. Hence we can memorize the hash value of these number by `hashNumber(m)` where `1 <= m <= 10^9` and `m` is power of 2, that is, we can construct a `unordered_set` :\n\n```cpp\nauto mp = unordered_set<int>(); /// our map which is used to store the hash value.\nauto number = int(1); /// our iteration of power of 2.\nwhile (number <= 1e9) { /// loop the number until it is bigger than 10^9.\n mp.emplace(hashNumber(number)); /// insert a hash value of number into our map.\n number <<= 1; /// iterate the number by multipling it by 2\n}\n```\n\nFinally, we have a constant `unordered_set`:\n``` cpp\nunordered_set<int> hashes{\n 10, 100, 10000, 100000000, 1000010, 1100,\n 1010000, 100000110, 1100100, 100110, 10111, 100010101,\n 1001010001, 1100000110, 101011010, 111001100, 2201000, 10001121,\n 1020210, 200110200, 111110011, 1010100211, 1000031011, 401001001,\n 32000120, 223100, 212010011, 120011220, 102221100, 1111101111};\n```\n\n---\n\n# **Source Code**\n\n``` cpp\nclass Solution {\nprivate:\n inline const static unordered_set<int> hashes{\n 10, 100, 10000, 100000000, 1000010, 1100,\n 1010000, 100000110, 1100100, 100110, 10111, 100010101,\n 1001010001, 1100000110, 101011010, 111001100, 2201000, 10001121,\n 1020210, 200110200, 111110011, 1010100211, 1000031011, 401001001,\n 32000120, 223100, 212010011, 120011220, 102221100, 1111101111};\n\n int hashNumber(int n) {\n auto res = int(0);\n while (n != 0) {\n res += int(pow(10, n % 10));\n n /= 10;\n }\n return res;\n }\n\npublic:\n bool reorderedPowerOf2(int n) {\n return hashes.find(hashNumber(n)) != hashes.end();\n }\n};\n```\n# **Complexity**\n\n- **Time**: `O(number_of_digits(n))`\n- **Space**: `O(1)`\n\n\n\n\n | 2 | 0 | ['C'] | 1 |
reordered-power-of-2 | c++ simple straight forward solution | c-simple-straight-forward-solution-by-ar-1npo | \nclass Solution {\npublic:\n bool checkdigits(int n,vector<int>&v)\n {\n vector<int>v1(10,-1);\n while(n)\n {\n v1[n%10]+ | arpitrathaur9 | NORMAL | 2022-08-26T05:58:01.896406+00:00 | 2022-08-26T05:58:01.896454+00:00 | 18 | false | ```\nclass Solution {\npublic:\n bool checkdigits(int n,vector<int>&v)\n {\n vector<int>v1(10,-1);\n while(n)\n {\n v1[n%10]++;\n n=n/10;\n }\n if(v1==v)\n return true;\n return false;\n }\n bool reorderedPowerOf2(int n) {\n vector<int>v(10,-1);\n while(n)\n {\n v[n%10]++;\n n=n/10;\n }\n int num=1;\n for(int i=1;i<=30;i++)\n {\n if(checkdigits(num,v))\n return true;\n num=num*2;\n }\n return false;\n }\n};\n``` | 2 | 0 | [] | 0 |
reordered-power-of-2 | ✅100% Faster || C++ Solution || Easy-understanding || Simple | 100-faster-c-solution-easy-understanding-g56o | \nclass Solution {\npublic:\n \n vector<int> gem(long int n) {\n vector<int>nums(10);\n \n while(n){\n nums[n%10]++;\n | StArK19 | NORMAL | 2022-08-26T05:47:00.289527+00:00 | 2022-08-26T05:47:00.289580+00:00 | 37 | false | ```\nclass Solution {\npublic:\n \n vector<int> gem(long int n) {\n vector<int>nums(10);\n \n while(n){\n nums[n%10]++;\n n=n/10;\n }\n return nums;\n }\n bool reorderedPowerOf2(int n) {\n vector<int>arr=gem(n);\n for(int i=0;i<31;i++){\n if(arr==gem(1<<i)){\n return true;\n }\n }\n return false;\n }\n \n};\n``` | 2 | 0 | ['C', 'C++'] | 0 |
reordered-power-of-2 | Approach: Converting into string, MAX TC: O(33*9*log(9)) i.e. O(1) constant time | approach-converting-into-string-max-tc-o-88k3 | \nclass Solution {\npublic:\n \n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n for(int i=0; | Niraj03 | NORMAL | 2022-08-26T05:45:00.048824+00:00 | 2022-09-02T03:51:30.585070+00:00 | 17 | false | ```\nclass Solution {\npublic:\n \n bool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n for(int i=0;i<33;i++){\n string x = to_string((long long)pow(2,i));\n sort(x.begin(),x.end());\n if(s==x){\n // cout<<s<<" "<<x<<endl;\n return true;\n }\n \n }\n \n return false;\n \n }\n};\n``` | 2 | 0 | ['String', 'C'] | 0 |
reformat-the-string | C++ SIMPLE EASY WITH EXPLANATION | c-simple-easy-with-explanation-by-chase_-ehx3 | \nclass Solution {\npublic:\n string reformat(string s) {\n string a="",d="";\n // split string into alpha string and digit strings\n fo | chase_master_kohli | NORMAL | 2020-04-22T15:02:04.788771+00:00 | 2020-04-23T03:15:43.277479+00:00 | 5,008 | false | ```\nclass Solution {\npublic:\n string reformat(string s) {\n string a="",d="";\n // split string into alpha string and digit strings\n for(auto x:s)\n isalpha(x)?a.push_back(x):d.push_back(x);\n \n // if difference is more than 1, return "" since not possible to reformat\n if(abs(int(a.size()-d.size()))>1)\n return "";\n // merge the strings accordingly, starting with longer string\n bool alpha=a.size()>d.size();\n int i=0,j=0,k=0;\n while(i<s.size()){\n if(alpha){\n s[i++]=a[j++];\n }\n else{\n s[i++]=d[k++];\n }\n alpha=!alpha;\n }\n return s;\n }\n};\n``` | 59 | 2 | [] | 4 |
reformat-the-string | [Python] Simple solution | python-simple-solution-by-katapan-lxmc | \n def reformat(self, s: str) -> str:\n a, b = [], []\n for c in s:\n if \'a\' <= c <= \'z\':\n a.append(c)\n | katapan | NORMAL | 2020-04-19T04:37:46.832331+00:00 | 2020-04-19T04:37:46.832379+00:00 | 4,697 | false | ```\n def reformat(self, s: str) -> str:\n a, b = [], []\n for c in s:\n if \'a\' <= c <= \'z\':\n a.append(c)\n else:\n b.append(c)\n if len(a) < len(b):\n a, b = b, a\n if len(a) - len(b) >= 2:\n return \'\'\n ans = \'\'\n for i in range(len(a)+len(b)):\n if i % 2 == 0:\n ans += a[i//2]\n else:\n ans += b[i//2]\n return ans\n``` | 42 | 1 | [] | 8 |
reformat-the-string | python, fast (>99%) and very easy to read, detailed explanation with tips | python-fast-99-and-very-easy-to-read-det-i5v9 | \nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n\t\t\n for c in list(s):\n if c.isalpha():\n | rmoskalenko | NORMAL | 2020-04-21T21:56:07.309459+00:00 | 2020-04-22T17:56:23.995534+00:00 | 1,986 | false | ```\nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n\t\t\n for c in list(s):\n if c.isalpha():\n a.append(c)\n else:\n n.append(c)\n \n if abs(len(a)-len(n))<2:\n while a and n:\n r += a.pop()+n.pop()\n if a:\n r = r + a.pop() \n elif n:\n r = n.pop() + r\n return r\n```\n\nSo how does it work? Let\'s start with a bit longer but more readable version:\n\n```\nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n for c in list(s):\n if c.isalpha():\n a.append(c)\n else:\n n.append(c)\n while a and n:\n r += a.pop()+n.pop()\n if not a and not n:\n return r\n elif len(a)>1 or len(n)>1:\n return \'\'\n elif a:\n return r + a.pop() \n elif n:\n return n.pop() + r\n```\n\t\n\tFirst, we define variables:\n\t\n```\n r,a,n = \'\',[],[]\n```\n\n`r` - is going to be our result\n`a` - a list of alphas\n`n` - a list of numbers\n\nNow we separate the alphas and the numbers. Here we use a simple single pass approach:\n\n```\n for c in list(s):\n if c.isalpha():\n a.append(c)\n else:\n n.append(c)\n```\n\nHere is the main loop:\n\n```\n while a and n:\n r += a.pop()+n.pop()\n```\n\nwe try to pick a pair `alpha+number` and append to the `r` until we have elements in both `a` and `n`.\n\nHere is one tip. Here we use `.pop()` to take elements from the list instead of a pointer. Why? A nice thing about `pop()` is you can save some variables because you can use the length of the array as a pointer to the next available element. Also, we clearly separate the processed elements from the ones we haven\'t worked on. It\'s a nice trick, can be used in other solutions too.\n\nOk, once the loop is finished, we go through 4 possible scenarios:\n\n1. both `a`/`n` are empty. That means we got equal number of alphas and numbers, so we can return `r`.\n2. one of `a` or `n` has more than 1 element left. That means in the input was out of balance and we can\'t form a valid output, so we return ``\n3. we have only one alpha or number. Since our `r` strings consists of `alpha+number` pairs, the last number should be prepended and the last alpha should be appended.\n\n```\n if not a and not n:\n return r\n elif len(a)>1 or len(n)>1:\n return \'\'\n elif a:\n return r + a.pop() \n elif n:\n return n.pop() + r\n```\n\nThat\'s it. While this code is not the shortest, it\'s structured in a way to make it easy to understand and it\'s fairly efficient since it\'s based on 2 single passes with minimal logic applied.\n\nCan it be improved? One obvious thing is we can check if alphas/numbers are out of balance before the main loop. Also, having multiple return statements makes it harder to understand the flow, so we can easily change it to use a single return statement.\n\nSo if we modify it to:\n\n```\nclass Solution:\n def reformat(self, s: str) -> str:\n r,a,n = \'\',[],[]\n for c in list(s):\n if c.isalpha():\n a.append(c)\n else:\n n.append(c)\n \n if abs(len(a)-len(n))<2:\n while a and n:\n r += a.pop()+n.pop()\n if a:\n r = r + a.pop() \n elif n:\n r = n.pop() + r\n return r\n```\n\nThis makes the logic just slightly harder to understand (because we do some checks before and some after the main loop), but now we can get into >99% range performance wise.\n\n\n\n | 35 | 0 | [] | 7 |
reformat-the-string | [Java] Use Character.isDigit() | java-use-characterisdigit-by-pwaykar-79ay | Understand the problem\n1. Reformat the string with alternate digit and character, and vice versa.\n2. Create 2 lists one for digits and the second one as chara | pwaykar | NORMAL | 2020-04-19T04:35:36.912773+00:00 | 2020-04-20T05:18:00.328820+00:00 | 4,116 | false | **Understand the problem**\n1. Reformat the string with alternate digit and character, and vice versa.\n2. Create 2 lists one for digits and the second one as characters\n3. Traverse the string and segregate the items to reformat\n4. Use a boolean to switch between character and digit and append all the items\n```\npublic String reformat(String s) {\n \n if(s == null || s.length() <= 1) {\n return s;\n }\n List<Character> digits = new ArrayList<>(s.length());\n List<Character> characters = new ArrayList<>(s.length());\n // Check if it is a digit or character\n for (char ch : s.toCharArray()) {\n if (Character.isDigit(ch)) {\n digits.add(ch);\n } else {\n characters.add(ch);\n }\n }\n // it is impossible to reformat the string.\n if(Math.abs(digits.size() - characters.size()) >= 2) return "";\n \n StringBuilder result = new StringBuilder();\n // boolean to decide if we should start with characters or digits\n boolean digitOrChar = (digits.size() >= characters.size()) ? true : false; \n\n for (int i = 0; i < s.length(); i++) {\n if (digitOrChar) {\n if (digits.size() > 0) {\n result.append(digits.remove(0)); \n }\n } else {\n if (characters.size() > 0) {\n result.append(characters.remove(0)); \n }\n }\n digitOrChar = !digitOrChar;\n }\n return result.toString();\n }\n``` | 30 | 3 | [] | 14 |
reformat-the-string | [Python] Clean solutions with explanation. O(N) Time and Space. | python-clean-solutions-with-explanation-30tsf | First we get lists of letters and digits seperately. \nThen we append the bigger list first. In this problem, i use flag to keep track of which one to append, t | jummyegg | NORMAL | 2020-04-19T06:53:16.614977+00:00 | 2020-04-19T07:11:09.174871+00:00 | 2,280 | false | First we get lists of letters and digits seperately. \nThen we append the bigger list first. In this problem, i use flag to keep track of which one to append, this will make the code cleaner.\n**1st Solution**\n```python\nclass Solution:\n def reformat(self, s: str) -> str:\n letters = [c for c in s if c.isalpha()]\n digits = [c for c in s if c.isdigit()]\n if abs(len(letters) - len(digits)) > 1: return ""\n \n rv = []\n flag = len(letters) > len(digits)\n while letters or digits:\n rv.append(letters.pop() if flag else digits.pop())\n flag = not flag\n return rv\n```\n\n**Another** pythonic solution. Inspired from [post](https://leetcode.com/problems/reformat-the-string/discuss/586674/Python-Simple-solution)\nThe idea is to swap a and b such that `len(a) > len(b)`\n```python\n # Different Pythonic solution\n def reformat(self, s: str) -> str:\n a = [c for c in s if c.isalpha()]\n b = [c for c in s if c.isdigit()]\n if len(a) < len(b): a, b = b, a\n if len(a) - len(b) > 1: return ""\n \n rv = []\n while a:\n rv.append(a.pop())\n if b: rv.append(b.pop())\n return rv\n``` | 20 | 1 | ['Python', 'Python3'] | 4 |
reformat-the-string | Java just count num of digits and letters | java-just-count-num-of-digits-and-letter-4axj | \npublic String reformat(String s) {\n if (s == null || s.length() == 0) return "";\n int ds = 0, as = 0;\n char[] arr = s.toCharArray(), r | hobiter | NORMAL | 2020-06-04T01:28:54.231563+00:00 | 2020-06-04T01:28:54.231598+00:00 | 1,603 | false | ```\npublic String reformat(String s) {\n if (s == null || s.length() == 0) return "";\n int ds = 0, as = 0;\n char[] arr = s.toCharArray(), res = new char[s.length()];\n for (char c : arr) {\n if (Character.isDigit(c)) ds++;\n else if (Character.isLetter(c)) as++;\n else return "";\n }\n if (Math.abs(as - ds) > 1) return "";\n boolean isDigit = ds >= as;\n for (int i = 0, d = 0, a = 0; i < arr.length; i++) {\n if (isDigit) {\n while (!Character.isDigit(arr[d])) d++;\n res[i] = arr[d++];\n } else {\n while (!Character.isLetter(arr[a])) a++;\n res[i] = arr[a++];\n } \n isDigit = !isDigit;\n }\n return String.valueOf(res);\n }\n\n``` | 17 | 1 | [] | 4 |
reformat-the-string | [C++] Count and Display | c-count-and-display-by-orangezeit-wdd9 | Version 1\ncpp\nclass Solution {\npublic:\n string reformat(string s) {\n int c1(0), c2(0);\n unordered_map<char, int> cnts;\n \n | orangezeit | NORMAL | 2020-04-19T04:39:36.552050+00:00 | 2020-04-19T13:40:15.677916+00:00 | 1,583 | false | Version 1\n```cpp\nclass Solution {\npublic:\n string reformat(string s) {\n int c1(0), c2(0);\n unordered_map<char, int> cnts;\n \n for (const char& c: s) {\n isalpha(c) ? c1++ : c2++;\n cnts[c]++;\n }\n \n if (abs(c1 - c2) > 1) return "";\n \n string ans;\n for (int i = 0; i < s.length(); ++i) {\n\t\t // if c1 >= c2, "letter-number-letter..."\n\t\t\t// otherwise, "number-letter-number..."\n string t = (i % 2) ^ (c1 >= c2) ? "az" : "09";\n for (char c = t[0]; c <= t[1]; ++c) {\n if (cnts[c]) {\n cnts[c]--;\n ans += c;\n break;\n }\n }\n }\n \n return ans;\n }\n};\n```\n\nVersion 2: Less Space\n```cpp\nclass Solution {\npublic:\n string reformat(string s) {\n int c1(0), c2(0), i(0), j(0);\n \n for (const char& c: s)\n isalpha(c) ? c1++ : c2++;\n \n if (abs(c1 - c2) > 1) return "";\n \n string ans;\n \n while (ans.length() < s.length())\n if ((ans.length() % 2) ^ (c1 > c2)) {\n while (isdigit(s[i])) i++;\n ans += s[i++];\n } else {\n while (isalpha(s[j])) j++;\n ans += s[j++];\n }\n \n return ans;\n }\n};\n``` | 10 | 1 | [] | 1 |
reformat-the-string | JavaScript O(n) simple solution | javascript-on-simple-solution-by-hon9g-j3wi | Time Complexity: O(n)\n- Space Complexity: O(n)\nJavaScript\n/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n let a = [], | hon9g | NORMAL | 2020-04-19T05:42:17.504887+00:00 | 2020-04-19T05:42:17.504920+00:00 | 676 | false | - Time Complexity: O(n)\n- Space Complexity: O(n)\n```JavaScript\n/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n let a = [], b = [];\n for (x of s) {\n isNaN(x) ? a.push(x) : b.push(x);\n }\n if (a.length < b.length) {\n [a, b] = [b, a];\n }\n return a.length - b.length <= 1\n ? a.map((x, i) => x + (b[i] ? b[i] : \'\')).join(\'\')\n : \'\';\n};\n``` | 9 | 2 | ['JavaScript'] | 0 |
reformat-the-string | Why "leetcode" => "", but "j" => "j"?? | why-leetcode-but-j-j-by-votrubac-futm | I got 10 minutes penalty because of that. This problem was not tested properly.\n\nThey must have something like that in the OJ solution:\n\n\tif (s.size() <= 1 | votrubac | NORMAL | 2020-04-19T04:01:15.660636+00:00 | 2020-04-19T04:12:29.494700+00:00 | 674 | false | I got 10 minutes penalty because of that. This problem was not tested properly.\n\nThey must have something like that in the OJ solution:\n```\n\tif (s.size() <= 1)\n\t\treturn s;\n``` | 9 | 5 | [] | 7 |
reformat-the-string | Beats 100% of users with C++ || Using Add String Alternative Approach || Best Solution || | beats-100-of-users-with-c-using-add-stri-1clj | Intuition\n Describe your first thoughts on how to solve this problem. \n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the approach pleas | abhirajpratapsingh | NORMAL | 2023-12-21T16:42:55.739650+00:00 | 2023-12-21T16:42:55.739692+00:00 | 426 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1-\nfirst we create two string first is for alphabet then second one is for digit \n\n2-\nthen we check if the both length absolute difference is greater than 1 then we return false\n\n3-\nthen we check if alphabet length is greater then digit length string then we first we set alphabet then digit alternatively\n\n4-\nthen we check if digit length is greater then alphabet length string then we first we set digit then alphabet alternatively\n\n5-\nreturn the string\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O ( N )\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n string reformat(string s) \n {\n int alpha_len=0;\n int digit_len=0;\n string alphaStr="";\n string digitStr="";\n for(int i=0;i<s.length();i++)\n {\n if(s[i]>=\'a\' && s[i]<=\'z\')\n alphaStr=alphaStr+s[i];\n else if(s[i]>=\'0\' && s[i]<=\'9\')\n digitStr=digitStr+s[i];\n }\n alpha_len=alphaStr.length();\n digit_len=digitStr.length();\n if(abs(alpha_len-digit_len)>1)\n return "";\n if(alpha_len>digit_len)\n {\n int i=0;\n int j=0;\n string ans="";\n while(i<alpha_len && j<digit_len)\n {\n ans=ans+alphaStr[i]+digitStr[j];\n i++;\n j++;\n }\n ans=ans+alphaStr[i];\n return ans;\n }\n else\n {\n int i=0;\n int j=0;\n string ans="";\n while(i<digit_len && j<alpha_len)\n {\n ans=ans+digitStr[i]+alphaStr[j];\n i++;\n j++;\n }\n if(digit_len!=alpha_len)\n ans=ans+digitStr[i];\n return ans;\n }\n }\n};\n``` | 6 | 0 | ['String', 'C++'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.