You are not logged in. Please login at to post your questions!


Confusion about TLE in a question. This is the question i was attempting.Here is my code getting TLE .This is another solution by one @gargmehul10 getting AC with a time of 0.59 s. Even though my code uses lesser loops and we both followed the same concept, mine gets a TLE. Can someone please explain?

asked 31 Oct '17, 19:20

kriskhundu's gravatar image

accept rate: 0%

edited 31 Oct '17, 19:23

Reason for TLE:

The code by @gargmehul10 executes the sieve only once inside main() for all the t test cases.

Your code executes the sieve t times for t test cases.

You are calling solve() which contains the sieve for all the t test cases.

Consider putting the sieve part in one function and call it just once before answering the test cases.

I hope this cleared your doubt.

All the best!


answered 31 Oct '17, 19:45

alfarhanzahedi's gravatar image

accept rate: 33%

edited 31 Oct '17, 19:47

Thank you very much! Doubt cleared.

(31 Oct '17, 20:04) kriskhundu3★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 31 Oct '17, 19:20

question was seen: 348 times

last updated: 31 Oct '17, 19:47