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.
The crucial point here is to generate permutations without duplicates like C++ std::next_permutation(). I don't think using itertools.permutations is appropriate here. Also, skip those permutations with preceding zeros. (e.g. start with 100000000003 instead of 000000000013) Then you won't get into TLE trouble with cases like 15 0, 24 0, 31 0, 33 0, 34 0 and 35 0. And don't forget the prime .
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #111: Primes with runs
You are viewing a single comment's thread. Return to all comments →
The crucial point here is to generate permutations without duplicates like C++
std::next_permutation()
. I don't think usingitertools.permutations
is appropriate here. Also, skip those permutations with preceding zeros. (e.g. start with100000000003
instead of000000000013
) Then you won't get into TLE trouble with cases like15 0
,24 0
,31 0
,33 0
,34 0
and35 0
. And don't forget the prime .