Prateek Loves Candy

4th test case is not passing. Please help why.

Hi @akankshaanand99 you are iterating over the sieve and finding the nth prime number every time. Since the number of test cases are also large, it will make a time complexity of o(t*n). You can simply make an array of prime numbers with the help of the sieve, this will take o(n) time and return the ith index of that array, which will take o(1) time. Refer to this code if you are confused about the implementation.

I did not understand.

@akankshaanand99 please have a look at the code I have shared above.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.