I think the following solution is quite efficient still I get time limit exceeded.
Any chances of relaxing the TLE or any suggestions on how to reduce the running time of my implementation?
def countPrimes(self, n): if n < 2: return 0 sieve =  * (n-1) ptr = 2 while ptr < len(sieve) - 1: if sieve[ptr] == 0: ptr = ptr + 1 continue new_ptr = ptr + ptr while new_ptr < len(sieve): sieve[new_ptr] = 0 new_ptr = new_ptr + ptr ptr += 1 return sum(sieve) - 2
I am getting similar error "Time limit exeeds". However, I have checked out my code until about 5 million which runs reasonably fast, within few seconds. I haven't heard from anyone on the discussion forum yet.
I see.. I actually pruned it down and this runs reasonably fast. I don't think we should be penalized for using "a slower language". Since, this is a new problem, I am sure the time limit will be fixed soon by the authors.
Note to self: don't jump too quickly on problems which are recently added to leetcode.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.