We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
1) For each N, you only need to loop from 10^((N-1)/2) to 10^(N/2). For example: N=4, i runs from 31 to 100. Then take i^2. That saves a lot of time complexity compared with i running from 1000 to 10000 and then taking square root.
2) A nice trick to store all permutations in any permutation problems: create a dictionary, convert satisfied number as a sorted key. For example: {'1269': [1296, 2916, 9216]}, where '1269' is sorted key of 1296, 2916 and 9216
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #98: Anagramic squares
You are viewing a single comment's thread. Return to all comments →
Hints:
1) For each N, you only need to loop from 10^((N-1)/2) to 10^(N/2). For example: N=4, i runs from 31 to 100. Then take i^2. That saves a lot of time complexity compared with i running from 1000 to 10000 and then taking square root.
2) A nice trick to store all permutations in any permutation problems: create a dictionary, convert satisfied number as a sorted key. For example: {'1269': [1296, 2916, 9216]}, where '1269' is sorted key of 1296, 2916 and 9216