Tips and Tricks to crack Competitive Programming: How do I Learn to Code? This is the most frequent question at the back of your mind if you are programmer.

It is great to here people start responding on my articles. This is requested articles from one of the readers. So enjoy post on your desire topic

Here I will guide those people who want to get started with competitive programming.

Competitive programming is just “PRACTICE, PRACTICE, AND PRACTICE”.

there is no standard process to learn code. there are guidelines but there is no one correct way.

Tips and Tricks to crack Competitive Programming

Pick an online judge. Recommended ones are Topcoder,  Codeforces    ,SPOJ,    CodeChef and HackerEarth.. These sites have high-quality problems and allow you to see another’s code post contest completion.



participate in three contests every month. Do participate in CodeChef LunchTime for sure.

Even if you are unable to solve a problem do always look at the editorials and then code it and get it accepted (this is the way you will learn).

And even if you are able to do it, do look at the codes of some good coders. See how they have implemented. Again you will learn.

The Same point applies to TopCoder and Codeforces as well.


4 to 5 short contests of 2 hour in a month (Do them once you develop some confidence).


Once you have proper experience and you can write codes very fast.

Tips and Tricks to crack Competitive Programming

  • Start with simple problems that typically require transforming English to code and does not require any knowledge of algorithms. Solving Div 2 250 (Division 2, 250 points) in Topcoder or Div 2 Problem A in Codeforces is a good start.
  • In the early stages of programming, people tend to write long pieces of code, which is actually not required. Try to keep the codes short and simple.
  • Read the codes of highly rated programmers. Compare your solution with them. You can see that it is simple and shorter than your solution. Analyze how they have approached and improve your implementation skills.
  • Read the editorials after the contest. You can learn how to solve the problems that you were not able to solve in the contest and learn alternative ways to solve the problems which you could solve.
  • Do not spend too much time if you are not getting the solution or are stuck somewhere.
  • After you feel that you have spent enough time, look at the editorials. Understand the algorithm and code it. Do not look at the real solution before you have attempted to write the code on your own.
  • Programming is a very practical and hands-on skill. You have to continuously do it to be good at it. It’s not enough to solve the problem theoretically. You have to code it and get the solution accepted. Knowing which algorithm/logic to use and implementing it are two different things. It takes both to be good at programming.

Some algorithms that you should learn

  1. Graph algorithms: Breadth first search (BFS), Depth first search(DFS), Strongly connected components (SCC), Dijkstra, Floyd-Warshall, Minimum spanning tree(MST), and Topological sort
  2. Dynamic programming: Standard dynamic programming problems such as Rod Cutting, Knapsack, Matrix chain multiplication, etc
  3. Number theory: Modular arithmetic, Fermat’s theorem, Chinese remainder theorem(CRT), Euclidean method for GCD, Logarithmic Exponentiation, Sieve of Eratosthenes, and Euler’s totient function
  4. Greedy: Standard problems such as Activity selection
  5. Search techniques: Binary search, Ternary search, and Meet in the middle
  6. Data structures (Basic): Stacks, Queues, Trees, and Heaps
  7. Data structures (Advanced): Trie, Segment trees, Fenwick tree or Binary indexed tree(BIT), and Disjoint data structures
  8. Strings: Knuth Morris Pratt (KMP), Z algorithm, Suffix arrays/Suffix trees (a bit advanced algorithms)
  9. Computational geometry: Graham-Scan for convex hull, and Line sweep
  10. Game theory: Basic principles of Nim game, Grundy numbers, and Sprague-Grundy theorem

The list is not complete, but these are the ones that you catch very often in the contests.


Read more