Many readers of this blog use to take part in online programming competitions and there are several problems, which are run-time bound. Usually when one gets a time-out error, one tries to revisit one’s logic. That’s the first thing to do but if you still are not making required progress you can try following tips:


Use printf, scanf over cin and cout: To get faster I/O operations. If you have enormous data to read, this will help you for sure.

Keep an eye on STL usage: STL is excellent for lessen your efforts and provide very smart inbuilt methods for many complex tasks but on the cost of time. An intelligent programmer can save time writing his/her own methods.

Note: This might cause you to take longer to solve a problem and STL beautify your code with fewer efforts. I personally love STL and everyone should use it in practice. But this can be a significant contributor in time-out frequently.


If you are using hash, avoid hash[“string”] it performs badly in terms of space and time. Use hash[:symbol] instead.


  • Avoid nested loops
  • Check boundaries carefully
  • Take care of program stack; not many folds/unfolds.
PS: Above is a small list of speed checkup; I urge everyone to contribute through comments to the post.

Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.