Category Archives: Algorithm

Count number of 2’s in a given range (0 to n)? (ex: range between 0-20, Ans: 3 (i.e [2], 1[2], [2]0))

Google Search:



Programmer/Engineers Quotes

  1. Change is the only constant. Don’t fear it and keep moving forward.
  2. Learn to ignore which/who doesn’t matter to you. Don’t let opinions of random people of “society” influence your decisions who don’t even understand you actually.
  3. Success is a relative term. Do what you are passionate about. Life is not always fair but if you do something out of love and passion, you got nothing to lose.
  4. Face your fear. Take risk. If you never attempt, you will never know what you are missing.
  5. Take control of your own life. If life is a car, you are the one who is driving it. Some people can give you company time to time but its ultimately your journey.



Java For Competitive Programmers


Java certification will worth in this case to learn the language good but problem solving with algorithms must be needed.


Java Certifications:

IT jobs with knowledge of coding without degree?

Honestly its very difficult. Since It company gives importance to degree and skills both.

There is no short-cut to success.


“Learning programming is much harder than learning any particular programming language. “

“Learning programming is much harder than learning any particular programming language. “


This statement applies only to ephemeral technologies, which you should only learn as needed anyway. That said, you’re going to learn a lot of them over your career.

Fundamental programming principles and techniques are eternal.




Array Implementation:

OOP Implementation with Array:


Practice Problem:

Where do I start competitive programming? I know the basics of C and C++.

Where do I start competitive programming? I know the basics of C and C++.

5 Answers

Rohit Surana

I would suggest you to first master C++ thoroughly. Since language is your weapon, a well sharped weapon is half job done 🙂

Then learn about basics of Data Structures like stacks queues, graphs, trees, and their implementation thoroughly. There are several youtube channels which have excellent tutorials on these topics. Finally solve Data Structures challenges on hackerrank.

Then study the C++ standard library which provides a robust implementation of all the Abstract Data Structures and some algorithms like sorting etc.

You can now start solving Warmup Challenges on Hackerrank in sorted order from easy to hard and then moving on to other domains. Hackerrank has the best UI as compared to other platforms also you can view various test cases. BUT you cannot view other people’s solutions.

Another good platform is codechef. Open Easy problems on CodeChef page. scroll down to the bottom of the page and start solving problems with most number of successful submissions. You can view other’s solutions on codechef so that you can get an idea of their thought process and style of code.

After practicing easy problems for 2 months. I would suggest to start learning various standard algorithms involving Dynamic Programming, Graphs, Trees, Greedy techniques, Number theory etc. Youtube has many good videos for these topics for ex. Excellent Dynamic Programming and other tutorials on Youtube by Tushar Roy .

There are many other good websites like Topcoder , HackerEarth, Sphere Online Judge (SPOJ) , Codeforces etc.

The is no shortcut to improve algorithmic thinking for competitive programming in a short time


Yeah. I like the question.

  1. You should learn the programming and modules by your own
  2. If there is a problem solve it perfectly it doesn’t matter how much time it takes.
  3. Learning part : Sorting algorithms, Data structures, Dynamic programming, Greedy algorithms(All basic part, you don’t need to remember the algorithm just catch the algorithm on the problem specification and can modify and apply)
  4. Please don’t be hurry in writing and submitting the code, just worry about the understanding the problem properly, analyse it step by step and then write your own algorithm as you understand and implement on the paper.
  5. Finally, Code the algorithm step by step as you want.
  6. Happy coding
14 Answers

Ashish Kedia

There is no short cut. And there is only one answer : Practice.

  • Take part in more short contest. They help you improve your speed of thinking. Long competition often have very hard problems that require more research and less thinking.
  • Take part in competitions as a team. It helps you see questions from a different point of view.
  • Discuss solutions with others after competition. That too helps understand you different solutions.
  • Take this course about learning how to learn.

Suchith Javagal (ಸುಚಿತ್)

Thanks for A2A, Ashwin Varghese

Unlike many people here I didn’t go too far with it. I had on and off relationship with competitive programming. Let me give a try. First of all, what do you mean by “short time”? I assume a semester – around 4 to 5 months. I also assume that you are comfortable with C++ or Java. Otherwise learn it first. You don’t need to learn Object Oriented Programming here. You won’t be dealing with design issues.

Grab “Competitive Programming – 3” by Steven and Felix Halim. Otherwise, continue reading….

What to do?

  1. In C++ learn Standard Template Library (STL) which contains the implementation of common data structures and algorithms. In Java, check out java.math, java.util and java.util.regex packages for the same.
  2. Learn mathematical topics like Number Theory, Graph Theory, Probability, Combinatorics, basic Geometry, Game theory, different proof methods etc. Later you might also have to learn Order Theory and little Abstract Algebra.
  3. Solve ad-hoc questions which require you to come up with your own algorithm instead of using or modifying standard algorithms. Also solve some problems which require mostly math.
  4. Learn data structures – Segment Tree, Fenwick Tree, Treap, Implicit Treap, Suffix Array / Automaton / Tree, Trie for String based problems, techniques on trees like finding Lowest Common Ancestors (LCA), Heavy Light Decomposition (HLD), Centroid Decomposition over the course of 5 months.
  5. Learn well-known algorithms – Fast exponentiation (applicable to matrices too), string searching – KMP or Z algorithm, basic graph theoretic algorithms to find MST, shortest path, solutions to well known problems like Knapsack problem etc.
  6. You hear terms like Dynamic programming (DP), greedy, Divide and Conquer, Brute Force etc. They are not algorithms, but problem solving paradigms. Know the difference. If you are scared of DP, then you are not alone.

The list of topics is not exhaustive. Have a look at these resources

  1. Data Science Tutorials – TopCoder tutorials
  2. MAXimal :: algo . It is in Russian. Use Google Translate. Some articles have been translated to English too – Main Page – E-Maxx Algorithms
  3. Data Structures and Algorithms
  4. Awesome resource for DS and Algorithms
  5. What are the “must known” algorithms for online programming contests?
  6. GeeksforGeeks | A computer science portal for geeks
  7. Mathematics for Computer Science – MIT OCW – For discrete mathematics.

How to do?

There are many good answers here. I’ll tell what I did. I started solving from most solved problems in SPOJ. I solved about 200+ most solved problems there. It taught me a lot of topics I mentioned earlier. Meanwhile, I used to participate in contests in Codechef, Codeforces and Hackerrank semi-regularly (do it regularly). Check out the editorial of the problems you haven’t solved during contest. If there is something new, learn and implement the idea on your own. Don’t give up until you get AC. (It is sometimes called ‘upsolving’). Then I solved problems from C and D ladder (in Codeforces) in A2OJ site.

Here is a a story – I took around two months to solve QTREE in SPOJ. I got plenty of WAs, rewrote the code thrice because it was very hard to find the bug. That was the first time I implemented Heavy light decomposition.


  1. It is okay to get frustrated because some topics are hard to learn and/or implement. It is okay to get Wrong Answer.
  2. Don’t compare yourself with “red coders” (top rated people) in the beginning. Remember that they have been doing it for years. It only leads to disappointment. They can be your inspiration though.
  3. Solve LOT of problems. Push yourself outside your comfort zone.
  4. Lot of practice is needed. That way, you learn to think and implement solutions pretty quickly over time.

Happy coding 🙂

Edit: Added resource for discrete mathematics. (Point 7 in resources section).

Akash Kandpal

Thanks for A2A,

I will try to answer this question. Imagine for next 6 months.

Stage 1: Setting up the base.(2 months)

Try solving first 200 problems in Sphere Online Judge (SPOJ) . for the first 2 months , try to do all the problems on your own. Stick with this for first 2 months till you gain confidence.

Stage 2: Moving to Code Chef(2 months)

Once you gain some confidence on SPOJ problems, move on to codechef and practice for next 2 months.

Stage 3: Moving to Top coder (2 months)
Now move to top coder and try competing in SRMs.

Practice daily , try solving 2 or 3 problems on your own. It might take an hour or 5 hours but do it on your own . Trust me after 2 months you will have a very good confidence in problem solving .

This is a sport , the more you train yourself the better you are. Hope this helps.

But if you want to prepare for cracking interviews then it will be better if you go for geekforgeeks and implement each and every algorithm out there in your own console and also keep a check to Wikipedia for learning new algorithms .

Tushar Nitave

Look, there is no shortcut for improving your thinking ability. It’s a slow process and you should be pertinacious. So, practice, practice and practice a lot!!!

Sorry that I didn’t give you direct answer to the question but, I hope you got my point.

Thank you.

Mohammad Abbas

You should try by developing logic. Solving problems in computing requires logical thinking and you need to improve that. Having a strong logic is very very helpful in programming competition, for instance, someone makes a program which runs in 10s, possibly you could make it run in less than 5s, and to do so, you need logic. Logic is the basic block of your program.

Having only a good logic won’t help. What would you do with an amazing logical way to tackle a problem if you don’t even understand the syntax? I guess you got what I mean. With great logic, one should know the language very nicely. You should know the insides and out of the language. You should be familiar with the language you’re about to code with and you should be able to understand each and everything written in the code. You can possibly have an amazing logic but the way you impelement that logic is more important. Being able to implement a task efficiently and smartly is the goal to a programming competition and once you have a good understanding of the language and an amazing logic, you can achieve the first prize.

Alex Langshur

By using those algorithms extensively on your own.

I’ve only recently gotten into competitive programming. However, my experience adopting the competitive programming logic and speed has been similar to the learning process behind non-competitive concepts.

Pull up that IDE, relax (you’re not being timed, don’t worry), and build something that makes use of that algorithm. The key to success is to understand how to use it and when to use it. Keep practicing with it on your own until you’re at a point of comfortability where you can pull it out of your inventory on short notice.

Don’t rush it either — it’ll take some time to get to the point where you can easily implement it in a competitive atmosphere.

Chetan Sharma

For most questions of these type the answer is doing deliberate practice. Absorbing practice. A kind of practice which is termed as being in “Flow”

Solving puzzles will help and do will reading good literature because I would prefer building a holistic mind.

Reading this book How to solve it A New Aspect of Mathematical Method:Amazon:Books will definitely help.

Solving puzzles on About – Project Euler will help.

Thinking about hard problems will also help. Your struggle to live with a complex problem and your inability to solve that problem and take that problem to your dreams will help too. Brooding over a complex problem will help too and so will taking help from your sub conscious mind will help too.

Playing a sport or doing some calisthenics will help too. Ideas is to send more oxygen to your brain.

Most importantly you will fail so many times that the motto Patience. Persistence. Perseverance will definitely help.

Egor Okhterov

I can answer you from the other end. How to improve in competitive programming very very slowly? I have an answer to that question.

You have to train on your own.

There is not a single person in this field who progressed fast alone. So, to answer your question we should just invert my previous advice:

You have to find a mentor.

Without mentor you will be progressing very slowly. No amount of practice and problem solving will replace a good trainer, who can see what is your current bottleneck and make you focus on that particular issue.

I was looking for a mentor for a few years already and could not find one, because I am too old (as they think). But you have time as an advantage and you should use it with the utmost care. The best step you could make at this stage towards your progress is to start actively looking for a mentor.

Praneet Sah

I can give you thousand ways to make your “thinking” better but everything drills down to just one word, PRACTICE!

I read somewhere, the worst programmer is the one who reads 100s of book but doesn’t practice anything.

So close Quora and get yourself to work!

Akash Agarwal

All of us like shortcuts don’t we, but the truth is that there is no shortcut. To get good at anything you need to spend time and train hard. Constant and deliberate practice makes you perfect or different from the average crowd in any field. The same principle applies here.

Keep solving problems, manage time wisely, work smart and don’t look back 🙂


Akilesh Murugan

It’s not easy but not very tough if you are determined—

1.>>>Takeup any program you want to write ..( can be any simple or complex program).

2.>>>Code it down on the comp.

3.>>>RUN IT !

4.>>>Now get back to the code you have written and check wether you can shorten down the length by bringing in more logical functions .

5.>>>Shorten the length of the code as much as you can .. (Now that will be the perfect code for that prgm).

————THIS is how you improve your algol thinking .————

The time i.e short or long time totally depends on you

Practice a lot .

Good Luck !

Vipul Srivastava

You have to pratice a lot. There are lots of algos you have to learn them then there are tons of variations of standard algos you have to practice them. Now it boils down to how much you can pracatice and how fast you can do it that is how many questions in how much time you can practice.

Practice is the one mantra which can guarantee your success in competitive coding world.

All the best..!!

Allakonda Harish

Yeah. I like the question.

  1. You should learn the programming and modules by your own
  2. If there is a problem solve it perfectly it doesn’t matter how much time it takes.
  3. Learning part : Sorting algorithms, Data structures, Dynamic programming, Greedy algorithms(All basic part, you don’t need to remember the algorithm just catch the algorithm on the problem specification and can modify and apply)
  4. Please don’t be hurry in writing and submitting the code, just worry about the understanding the problem properly, analyse it step by step and then write your own algorithm as you understand and implement on the paper.
  5. Finally, Code the algorithm step by step as you want.
  6. Happy coding

Mostafa Radwan

You should solve many different problems

and your think will be improve as a result of the difficulty of the problem you solved

Learning data structures and algorithms from scratch

Quora sources:

  1. Learn Big-Oh notation, omega and theta notations denoting complexity of algorithms and data structures.
  2. If you don’t know, learn some discrete mathematics and probability. Learn basic combinatorics, graph theory, matrices, probability theory, especially the concept of expected values. Do this on the fly.
  3. Learn basic data structures
    1. Implement singly and doubly linked lists on your own.
    2. Learn stack and queue. Implement them using linked lists. For more fun – try implementing stacks and queues using arrays.
    3. Implement vector data structure in C++ on your own. It is simple – when you run out of space, allocate twice the memory you had allocated previously and copy all the data to newly allocated array.
    4. Implement binary heap data structure and use it as priority queue.
  4. Learn sorting algorithms
    1. Learn somewhat inefficient sorting algorithms – Selection sort, Bubble sort and Insertion sort (the last one works fine on small inputs)
    2. Learn merge sort. Recursive functions can be somewhat hard to understand in the beginning. This teaches you that skill. Trace it very well.
    3. Learn quick sort. This is one of the most important algorithms ever discovered. Learn the importance of randomized quick-sort and pivot selection.
    4. Learn counting sort and why it works in linear sort.
    5. If you are interested, you can go further and learn about “stability” of sorting algorithms. For instance, merge sort and insertion sort are stable.
  5. Some more data structures now. Let’s go to the next level.
    1. Binary Search Tree – Implement the basic binary search tree and set operations using it – insert, delete, find elements in it.
    2. You might come across performance issues for certain inputs. Why? Now learn about “Balanced” binary search trees like AVL Tree and Red-Black Trees and try implementing them – This is hard, tedious and scary to implement and debug. Expect lot of Segmentation faults.
    3. Learn the concept of hashing and hash-table. Implement a hash-table. (there are two schemes).
    4. Figure out what else can be done with binary search trees. Augmenting data structures with more information? How about adding a feature where kth order statistic can be found? How about binary search on keys?
  6. You might have encountered terms like Divide and Conquer while studying merge sort. They are called “Algorithm design techniques”. You will also come across terms like Brute Force, Dynamic programming, Greedy algorithms. Now let’s dive into it.
    1. You already know Divide and Conquer. Learn Dynamic programming technique. You might find it a bit difficult in the beginning and all of us had been there. Study the solution of some standard problems like Rod Cutting, 0/1 Knapsack, Edit Distance, Matrix Chain Multiplication, Longest Increasing Subsequence etc.
    2. Now it is time to look at another technique – Greedy algorithms. Study standard problems which use greedy technique like selecting largest number of intervals among given ones so that there is no conflict. You’ll see more later.
    3. Learn the difference between all these techniques. DP and D&C differ in sub-problem overlap and Greedy, DP differ in the way decisions are made and revisited.
    4. Study the proofs of these algorithms, especially the greedy ones. Don’t worry about abstract concepts like Matroids for now.
  7. Let’s jump to Graph algorithms now.
    1. Let’s build a maze solver – Learn and implement Depth First Search (DFS) and Breadth First Search (BFS). They are basic searching techniques.
    2. Study Prim’s and Kruskal’s Minimum Spanning Tree algorithms and implement them.
    3. Let’s implement our version of Google Maps – Finding the shortest path between two given places given a roadmap. Learn and implement the algorithms of Dijkstra, Bellman-Ford and Floyd-Warshall.

Bingo, now you are pretty good at data structures and algorithms. But remember that this is just the tip of the iceberg. Once you learn it, implement on your own. Only then you get a feel of it. If you want to learn them in a fun way, try competitive programming.

Here are some resources

  1. Introduction to Algorithms – CLRS (Chapters are in the order I have written. I have skipped some chapters in it). I suggest this one along with the DSA course from Stanford on Coursera.
  2. Coursera – data structures and algorithms courses
    1. Algorithms, Part I – Princeton University | Coursera
    2. Algorithms, Part II – Princeton University | Coursera
    3. Algorithms | Coursera – from Stanford University
  3. MIT Open courseware
    1. Introduction to Algorithms (SMA 5503)
    2. Advanced Data Structures – As the course says, this is VERY advanced. If you are ready to go deeper, then go here.
  4. GeeksforGeeks – It is very helpful, especially if you are preparing for an interview.

Arunabh Ghosal

I was in the same situation 1 and a half year ago. I will explain how I learnt data structure and algorithms.

In the following text Algorithms and Data structure which are marked in bold are very important. Learn every algorithm/data structure with it’s time & space complexity, stable, in place, and where it is useful.

What to study?

Step 0 :

  • Understand about pointers in C++, structures or classes
  • Learn how to calculate worst case, best case , average case time complexities

Step 1 :

  • Learn few basic sorting algorithms along with their use case and time complexity.
    • Bubble sort
    • Insertion sort
    • Selection sort
  • Learn searching algorithms along with time complexity.
    • Linear Search
    • Binary Search

Step 2 :

  • Stack
  • Queue
  • Single Linked List (Insert at front,back,middle; Delete at front back middle)
  • Double Linked List
  • Circular Linked List

Step 3 :

  • Learn the following approaches in algorithms
    • Divide and Conquer (Merger Sort, Quick Sort, Binary Search are some examples)
    • Greedy method (Knapsack, Prim’s algorithm, Kruskal’s algorithm, Dijkstra, Bellmanford)
    • Dynamic programming (0/1 Knapsack, Travelling Salesman Problem, Coin change)
  • Backtracking (N Queens problem)

Step 4 :

  • Binary Tree
  • Binary Search Tree
    • Height of a Tree
    • Tree Traversal
      • BFS
      • DFS
    • Searching an element
  • AVL Tree
  • Hashing

Where to study from?

GeeksforGeeks | A computer science portal for geeks

Data Structures and Algorithms | Coursera

Video Lectures | Introduction to Algorithms (SMA 5503) | Electrical Engineering and Computer Science | MIT OpenCourseWare

Note: If detailed answer or specific approach is needed, feel free to massage me on quora.

Vaibhav Lawand

First thing you should know is how pointer works,how dynamic memory gets allocated and also basic concepts like stack unwinding etc.

Now assuming that your basics are clear, you should start with famous Thomas Cormen book; start implementing the algorithms on your own. At first, you’ll struggle but remember hard work is the key to success.

If you are not best at programming, then look for website. This website is the best to crack any coding interview.

Some more:

  1. Data structure course – Unlimited Online Developer, IT and Creative Training
  2. Udemy data structure course
  3. mycodeschool
  4. thenewboston – Youtube channel

Happy coding…!!!

Algo Book

Practice or Train ?

When it comes to competitive programming, the most important thing we need to have is patience. Of course, competitive programming requires a lot of hard work, consistency dedication. The term you used “practice smartly”, fits the best here. Well every competitive programmer sets short term goals and strategies to achieve them. Well here are some of the strategies that I follow and I think are smart enough to fit in your view:

  1. I choose one topic that I haven’t mastered yet. Find tutorials on that topic, mainly from the list given below:
    1. TechParoksha (not all kind of tuts are available, but the ones that are available, are awesome)
    2. Data Science Tutorials (Don’t go with the name)
    3. Algorithms – GeeksforGeeks
    4. Tracks and Practice Problems
  2. I study it (not necessarily master it at the first go). But I make sure to finish the most of it as soon as possible so that I could start it again as fresh. And believe me this makes the most out of it at the second attempt.
  3. Once I think I know this topic well enough, I immediately go to A2 Online Judge and find problems based on that particular topic. I prefer Sphere Online Judge (SPOJ)as my favorite online judge. But I would prefer to choose Codeforcesif I were to solve more number of problems instead of more difficult problems.
  4. Then I start solving problems in increasing level of difficulty. Since I choose Sphere Online Judge (SPOJ) most of the times, so I make sure not to give up, until the problem I chose is completely solved. Because I think problems here are the toughest and always make you more and more confident once you solve them.
  5. I don’t leave any live contest from any of the following websites:
    1. HackerRank
    2. Codeforces
    3. Programming Competition,Programming Contest,Online Computer Programming
    4. HackerEarth – Programming challenges and Developer jobs

Here are some other things that you might like:

  1. We, the competitive programmers, get bored easily. Make sure to go out and have some fresh air every once in a while, to get intense at it. You can use some other type of entertainment. My personal favorite is to solve an older codeforces round contest in virtual mode.
  2. Find a peer, that is equivalently passionate about competitive programming. Compete with him/her, that’s one of the best ways to manipulate laziness that you may feel sometimes.
  3. Set motivations(such goals). My latest motivation was to secure under 100 rank in hackerrank codesprint contest, so that I could get amazon gift card and a hackerrank t-shirt. But I couldn’t.

There is no other way for success, but practice to the hardcore level.

All the best! 🙂

Jobs For ACM Programmer

Trainee Software Engineer (Python)



Job Description / Responsibility
  • Possesses excellent technical skills as well as excellent problem solving skills.
  • Implement SDLC and coordinate with other members of the team.
  • Meet deadlines and achieve intended results.
  • Designs, develops and modifies modules based on functional and system requirements.
  • Work closely with the Team Leader, Business Analyst and Product Owner for understanding the functional and system requirements.
  • Work closely with the Architecture Team to ensure architectural integrity and product quality.
  • Participate in testing process through unit testing and bug fixes.
  • Participate in daily scrum meetings
  • Participate in sprint planning
  • Work closely with the QA team, Product Management team, and the Research and Development manager to ensure quality and punctual software development
Job Nature


Educational Requirements
  • B.Sc in Computer Science/ relevant degree/ equivalent working experience.
  • Freshers are encouraged to apply for the position.
Job Requirements
  • ACM problem solving skills will be considered as a good plus.Those who have solved 200+ ACM problems will get preference.
  • Good score on hacker Rank, UVA Online Judge, Top Coder or any other problem solving sites will be considered as a plus.
  • Clear concept of Object Oriented Programming
  • Experience with MVC frameworks.
  • Good knowledge in Javascript and working experience with jQuery.
  • Knowledge of algorithms and excellent problem-solving capability.
  • Knowledge on ORM is a plus
  • Knowledge on Python/Django is a plus
  • Knowledge on business application is a plus
Job Location


Salary Range
Other Benefits
    As per company policy.
Job Source Online Job Posting

Job Summary

Published on: Sep 22, 2016

Vacancy: 04

Job Nature: Full-time

Job Location: Dhaka

Salary Range: Negotiable

Application Deadline: Oct 22, 2016

What is the best strategy to improve my skills in competitive programming in 2-3 months?


This post has been taken from the blog post  Learn to Code by Competitive Programming written by MV Kaushik when he was interning at HackerEarth

Here are some steps to get started and be good at it.


    • Get comfortable writing code in either of one of these languages C, C++ or Java. Why only C, C++ or Java? Because these are the standard languages allowed in any programming competition.
    • If you are already good at C, it is suggested to learn C++. It is the most popular language among competitive programmers because of its speed and an excellent library in the form of STL (Standard Template Library).
    • Pick an online judge. Recommended ones are Topcoder and Codeforces. These sites have high quality of problems and also allow you to see other’s code post contest completion. These also categorize problems based on the topic. Some other popular judges include SPOJ, CodeChef (powered by SPOJ) andHackerEarth.
    • To begin with, start with simple problems that typically require transformingEnglish to code and does not require any knowledge on algorithms. Solving Div 2 250 (Division 2, 250 points) in Topcoder or Div 2 Problem A in Codeforces is a good start.
    • At the early stages of programming one tends to write long pieces of code, which is actually not required. Try to keep codes short and simple.
    • Practice these problems until you become comfortable that you can submit it for 240 odd points on any day.
    • Start implementing basic(or standard) algorithms. It is suggested to read them from Topcoder tutorials or Introduction to algorithms.1) Graph algorithms: Breadth first search(BFS), Depth first search(DFS), Strongly connected components(SCC), Dijkstra, Floyd-Warshall, Minimum spanning tree(MST), 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), Euclidian method for GCD, Logarithmic
      Exponentiation, Sieve of Eratosthenes, Euler’s totient function.

      3) Greedy:  Standard problems such as Activity selection.

      4) Search techniques: Binary search, Ternary search and Meet in the middle.

      5) Data structures (Basic): Stacks, Queues, Trees and Heaps.

      6) Data structures (Advanced): Trie, Segment trees, Fenwick tree or Binary indexed tree(BIT), Disjoint data structures.

      7) Strings: Knuth Morris Pratt(KMP), Z algorithm, Suffix arrays/Suffix trees. These are bit advanced algorithms.

      8) Computational geometry: Graham-Scan for convex hull, Line sweep.

      9) Game theory: Basic principles of Nim game, Grundy numbers, Sprague-Grundy theorem.

      The list is not complete but these are the ones that you encounter very frequently in the contests. There are other algorithms but are required very rarely in the contests.

    • You can find description and implementation of standard algorithms here
    • Once you have sufficient knowledge of popular algorithms, you can start solving the medium level problems. That is Div 2 all problems in Topcoder and Codeforces. It is advisable not to go for Div 1 500 at this point.
    • Learning to code is all about practicing. Participate regularly in the programming contests. Solve the ones that you cannot solve in the contest, after the contest. Apart from Topcoder and Codeforces you can also look at HackerEarth Challengesor Codechef contests.
    • Read the codes of high rated programmers. Compare your solution with them. You can observe that it is simple and shorter than your solution. Analyse 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.
    • Always practice the problems that you could solve in the contest. Suppose if you are able to solve Div 2 250 and 500 in the contest but not Div 2 1000 then practice as many Div 2 1000 problems as as you can.
    • 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 actual 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.
    • Programming learning phase is going to take a lot of time and the key is practicing regularly. It takes some time before you can attempt Div 1 500 and other tough problems. Do not give up on reading the editorials and implementing them, even if it takes many hours/days. Remember everything requires practice to master it.

It takes considerable amount of time before you get good at it. You have to keep yourself motivated throughout. Forming a team and practicing is a good choice. Not giving up is the key here.


Life Story of Anudeep Nekkanti – Competitive Programmer


Anudeep Nekkanti is an ACM contester who got to know about online judge in January, and by August he was the 35th on Global rank.

What he said about this:

What I did ?

  • Solved about 300 problems on SPOJ in this order – Sphere Online Judge (SPOJ)

Result ?

  • Became very good with C++ and STL
  • Got introduced to most Competitive programming KEYWORDS (like DP, maxflow, sets, hashing, etc)
  • Learned Standard Problems and Algorithms
  • Indenting code
  • Fast typing 😛

How ?
Before starting programming, I searched about how and where to start, many said “Learn an Algorithm, implement it, solve  problems related to it”. I did not do it that way, If you know what algorithm to use you generally think in that direction and leave about correctness.  I did them problem by problem, easy to hard, I spent 1 – 4 hours on a problem.
I get the idea, I code it, Get it Accepted. (I used to test a lot, I always wanted to get AC on first go)

I do not get the idea, I save that problem and try it after a month again. If I still do not get them, then search for hints. If it clearly needed some algorithm which I never used then I first smile (? I could not only because I did not knew the algorithm 😛 ) and then start reading about that algorithm. TopCoder had tutorials of almost all common algorithms. This is where I did a BIG MISTAKE. I never cared about correctness or run-time analysis proof, I always learned how to solve the problem using that algorithm, I hardly learned about how the algorithm works. I feel bad about it now, but that is how I solved those problems then. I solved max-flow, convex hull, etc., problems using described algorithms but I did not UNDERSTAND those algorithms then.

Mistake: Once I started taking part in contests, I completely stopped practice.

35th in Global Ranking

  • CodeChef long contests are comparatively easy ( Which is good, You can learn a lot), you get a lot of time to think about a problem, search for resources. You only need KEYWORDS to search for similar problems.
  • I gave a lot of time for each contest. I used to solve 4 easy problems in 2-3 days, then take 5-6 days for other 3 problems.
  • CodeChef rating system is not good. It is highly Volatile.

If I am to start programming now, I would do it this way

  1. Solve 200 most solved problems on SPOJ, Problem by problem. In 2 months.
    (This will teach all standard problems, algorithms and implementation skills)
  2. Solve problems from CodeChef and CodeForces for 2 months.
    (This will teach variations, we can read others solutions and learn better ways. Skip easy problems)
  3. Solve problems from TopCoder for 2 months.
    (This will teach  Dynamic Programming. Div 1 500p)
  4. Check past ACM ICPC Regional’s Problems
    (Great quality problems)

If I am to learn a new Algorithm now, I would do it this way

  1. Read it from at least 3-4 different sources.
  2. Understand correctness proof and run-time analysis.
    (This is very very important, you will know it only when you  deal with non standard  and hard problems)
  3. Question yourself on every step for correctness. Try to tweak the implementation.
  4. Check other implementations.

Final Note
Thought I became good in solving problems and had good rank. I later(Feb 13) realized that I learned it the wrong way. I then started learning again. I learned all the algorithms again this time gave importance to the algorithm itself, correctness proof and mathematical analysis. It is worth the time.

Lucy and the Flowers – Problem from December long contest, Try to solve it with suffix arrays. You can only if you understand suffix arrays and LCP completely.

I was able to solve a not-so-obvious medium level Max-Flow problem at ACM KGP Onsite only because I completely understood how the algorithm works. It was at 4 hour 25 minutes I got 5th problem accepted, then I read this problem and got it accepted 4 minutes before end. Learning the algorithm helped. Dot.

Some sites to learn Algorithm Data Structure