How to Start with Competitive Coding from Zero?
-Photo by Kobu Agency on Unsplash
This is a question that has haunted me for years, and I could never begin for a long time. Finally, it turned out to be a simple lesson: “Start by doing”, and that’s all that is required. The only problem in this statement is what exactly to start with.
I am from a non-CSE Department and chose to have a career in Software Engineering. So, I had to start from zero myself. After 8 months of coding practice, I landed an offer from a good MNC. Here I am laying down a simple step-wise plan that might help you to start from zero. Though it is not the only plan that would work and you don’t need to stick to it. But it helps to have a concrete plan to compare with in case you have your own road map. In fact, once you start having a hang of coding (after solving 60–80 easy-level questions), you would not even need to further follow this plan. But, it would still be handy to check if you miss any topic.
This post has six sections. The first section includes basic data structures and algorithms that you need to learn. Completing Section 1 might be helpful in coding tests of some companies. Section 2 includes Dynamic Programming and Greedy Algorithms. Completing Sections 1 and 2 will be good enough for fresher coding tests of most companies. Section 3 includes graphs that you encounter in coding tests of a few companies. Section 4 contains some other specific topics/data structures/algorithms that I have encountered in coding tests of a few companies. But, you won’t find questions too often on these topics but it’s better to learn them too if you could get enough time). Section 5 includes some extra topics/algorithms that are generally taught in Algorithms courses but are not important for placement tests. Section 6 includes FAQs about placements that I have encountered people asking in different forums.
It would be better if you approach and master these sections sequentially (except Section 4; you can do it with Section 3). But, you can have your own preference depending on what works best for you.
Note : Please note that I keep editing this article to best add all the relevant information/resources. I maintain a history of all the edits that I make so that it is easy for you to follow the changes. So, checkout the Edits Section at the end of this post if anything is added after you last visited the article.
Section 1
Let’s first have a look at the key things required for competitive coding:
- Programming Language
- Data Structures
- Algorithms
- Online Coding Practice
A. Programming Language
Edited Image from towardsdatascience
The first step is to choose a programming language (only choosing and not mastering). You only need to know some basic functionalities and shouldn’t bother about mastering it. Many people (including me) fall into the trap of trying to master the language before coding.
You could never learn a language without starting to use it.
So, to learn the required basic functionalities, head to HackerRankand log in/create your account. After login look for “Language Proficiency” Modules as shown in following image:
Choose a programming language and solve the first 15–20 questions. That’s it! Only the first 15–20 questions and you are all set with all the basic functionalities required. Don’t bother about the choice of the language at this point. If you are good at coding with one programming language, you can pick up any other. I coded with Python for around 7 months and then picked up C++ in 2–3 days. I first read some of its theory (see Resources at the end of this post) and then practised with it for next 3–5 days.
Note: If you don’t have a strict personal preference or are not sure about the programming language, here’s a point that may help you. I only know Python and C++ and so my point here is only about these two languages. If you are an absolute beginner, you will find it easier to start with Python than C++. But, you have to learn C++ because sometimes (only 1–2 companies like JP Morgan Quant Profile) don’t allow Python (I don’t know why). And, many companies ask questions about the output of a given C/C++ code in the form of MCQs and OOP concepts in C++. So, if you have around one semester (3–4 months) then Python may be your best bet as the learning will be fast with Python. But, if you have at least two semesters (8 months or more) then you can either choose C++ or Python first and then learn C++ later on (that’s what I did). But, learning will be slow initially with C++ but normal once you have enough practice.
B. Data Structures
Photo by Harsh Goel on HackerEarth
Data structures are the basic building blocks of competitive coding. It is better to first read about the basic data structures mentioned below.
- Array
- Linked List
- Stack
- Queue
- Strings
- Hashing* (Only usage, you can read theory later on)
- Binary Trees**
- Binary Search Trees**
- Heap**
You can learn about the above data structures from GeeksforGeeks. Read their theory and learn how to implement them in the programming language of your choice. GeeksforGeeks contains the implementation of these data structures in different programming languages.
Once you master and have some experience with these basic data structures (№1–6), you can go on to learn the complex ones mentioned at the end of this post.
*Note: I have mentioned hashing here because you may find it helpful in a lot of problems. You need not know its theory at this point. Most of the programming languages offer built-in implementation of hashing. But its theory is very important for coding interviews. You should check out its theory from the book Introduction to Algorithms mentioned in the Resources section.
**Note: I am not counting binary trees, binary search trees and heaps in basic data structures. And, you need not to finish them right now to move on to the next section. I have mentioned them here because there are lectures in the next section on these topics. So, complete only up to Hashing and move on to the next section. After completing lectures on trees and heaps in the next Section, you can learn their implementation from the above links.
C. Algorithms
Algorithms are the most important part of competitive programming. If you master algorithms, you are more than 50% done.
There is no substitute for a proper course on Algorithms. It would be better if you both watch a lecture and read from GeeksforGeeks. For example, the Algorithms course ( CS21003 ) offered by the CSE Department in my college (IIT Kharagpur) is good. I would recommend that you take that course (if possible) as a “depth/breadth” and not as an “additional” (for obvious reasons). CS21003 is offered in even semesters for non-CSE students. You can get the course if you have an 8+ CGPA. I am not sure about the below 8 CGPA because the cutoff depends upon all the students who have applied.
If you are from some other college or can’t take that course for some reason, I am adding relevant online lectures below. Feel free to skip these lectures if you are already taking any course in Algorithms.
I am not aware of many online courses on Algorithms except those provided by MIT OCW which you can find on their website or YouTube. MIT has many courses on Algorithms, and you may find it overwhelming to complete them. Moreover, it’s not required to complete them for fresher coding tests. So I am mentioning selective lectures from the courses MIT 6.006 Introduction to Algorithms, Fall 2011 and MIT 6.046J Design and Analysis of Algorithms, Spring 2015 that you can watch in the sequence mentioned below:
- [MIT 6.006] R1. Asymptotic Complexity, Peak Finding
- [MIT 6.006] R5. Recursion Trees, Binary Search Trees (only Recursion trees part)
- [MIT 6.006] Lec1: Algorithmic Thinking, Peak Finding
- [MIT 6.006] Lec2: Models of Computation, Document Distance
- Read about Recursive Thinking from GeeksforGeeks
- [MIT 6.006] Lec3: Insertion Sort, Merge Sort
- [MIT 6.006] Lec4: Heaps and Heap Sort
- [MIT 6.006] Lec5: Binary Search Trees, BST Sort
- [MIT 6.006] Lec7: Counting Sort, Radix Sort, Lower Bounds for Sorting
- [MIT 6.046J] Lec2. Divide & Conquer: Convex Hull, Median Finding
- [MIT 6.046J] R1. Matrix Multiplication and the Master Theorem (matrix multiplication is optional, but do check master theorem)
- [MIT 6.046J] R4. Randomized Select and Randomized Quicksort
The above lectures should be enough to start coding online.
While you are watching lectures, also start practising coding online. That is, suppose you finished a lecture on merge sort then you should try to code it yourself. You should always know to code the routines of all major sorting algorithms by yourself. For example, many companies have asked Array Inversion. You will need to write a modified routine of Merge Sort to get an O(nlogn) complexity. At this point, you already know a language and have completed basic data structures. So, you should also start doing questions about those data structures as explained in the next section.
D. Online Coding
Photo by Clément H on Unsplash
Practice is the ultimate key to mastering anything you want to learn.
There are several websites to practice coding like LeetCode, HackerRank, InterviewBit, Codeforces, and CodeChef. I have used only the first three. Start with LeetCode if you have at least two semesters (8 months) to prepare else start with InterviewBit.
So far, you have completed Data Structures and started Algorithms. So, head to the LeetCode Problems and filter out the questions based on topics that you have already covered. Then, sort the questions based on their level of difficulty. You should start with the Easy level questions. Easy doesn’t mean “easy” and you may not be able to solve them on your first try. Solve 10–15 questions on each of the topics that you have covered so far and then head to the next section.
Having done 10–15 Easy level questions on all the topics, you should start doing Medium level Questions on them. I would recommend that you should start doing Medium level questions once you start Section 2. Once you start doing Medium level questions, you would feel easy-level questions to be “easy”.
NOTE: InterviewBit has a programming practice track that you should complete for your coding tests. It includes questions that have already been asked in coding tests of different companies. And, you will find repetitions of many of these questions in your coding tests. So if you start with any other website like LeetCode, make sure that you also complete this track. It may take around 1–2 months to complete this track, so plan accordingly. If possible, also complete the Top 100 liked questions of LeetCode after completing the InterviewBit practice track as you may find many repetitions from there also. Don’t worry, you would have already solved most of these 100 questions during your practice.
Section 2
If you have come this far, then you would have gained very good coding skills. There are two important algorithmic paradigms that are important to master and I didn’t mention them in the above Algorithms section. These are Dynamic Programming and Greedy Algorithms. You can watch the following lectures for the same:
- [MIT 6.006] Lec19: Dynamic Programming I: Fibonacci, Shortest Paths
- [MIT 6.006] Lec20: Dynamic Programming II: Text Justification, Blackjack
- [MIT 6.006] Lec21. DP III: Parenthesization, Edit Distance, Knapsack
- [MIT 6.046J] R6. Greedy Algorithms (Also read about Greedy algorithms from GeeksforGeeks via example problems shown there. You need to practice a bit to develop an intuition on where you can use the Greedy approach.)
The path is like as above for these two topics. Watch the video lectures and then solve 10–15 questions on each topic. Dynamic Programming and Greedy approaches are important. Practice as many questions as you can on them.
Section 3
So far, you have covered almost everything required to be a good competitive programmer except graphs. If you still got time, you can go on to learn graphs*. You may find the following resources useful:
- Read about Graphs as a data structure on GeeksforGeeks
- Read about representations of Graphs from GeeksforGeeks
- [MIT 6.006] Lec13: Breadth-First Search (BFS)
- [MIT 6.006] Lec14: Depth-First Search (DFS), Topological Sort
- [MIT 6.046J] Lec12: Greedy Algorithms: Minimum Spanning Tree (This lecture includes Prim’s MST Algorithm and Kruskal’s MST Algorithm**)
- [MIT 6.006] Lec15: Single-Source Shortest Paths Problem (SSSP Problem)
- [MIT 6.006] Lec16: Dijkstra (for SSSP Problem)
- [MIT 6.006] Lec17: Bellman-Ford(for SSSP Problem)
- [MIT 6.046J] Lec.11: Dynamic Programming: All-Pairs Shortest Paths (ONLY Floyd Warshal Algorithm)
With graphs, you have covered almost everything required assuming that you were also practising online. There are some specific topics left that I have encountered sometimes in coding tests of a few companies. You can find these topics in the next section.
*NOTE : If you are overwhelmed with so much by now or don’t have much time for Graphs then finish only up to BFS (№3) and DFS (№4). BFS and DFS will be enough for 95–99% of the questions that you may encounter on Graphs in coding tests. Only 2–3 core CSE companies open for non-CSE students ask very difficult questions on graphs like Nutanix. So, don’t bother much about graphs for now. Additionally, you can learn Topological Sort.
**NOTE : For implementing Kruskal’s Minimum Spanning Tree Algorithm, you would need to learn Disjoint Data Set Structure. It’s mentioned in Section 4 and is a very helpful data structure for a lot of problems. You can read about it first from here and then here.
Section 4
I have encountered the following topics sometimes in coding tests of a few companies. You can read about them if you got enough time.
- Bits Manipulation : Bits manipulation is an important topic for coding as well as interviews. It can save you a lot of time and complexity in certain questions. Walmart asked questions only on Bits Manipulation this time in both the Coding and Data Science profiles. You can read about Bits Manipulation from HackerEarth Tutorial.
- Dequeue : I have found usage of Dequeues in only one specific question asked in the coding test of two companies. Both Python and C++ offer built-in implementation for Dequeues.
- Disjoint Set Union (DSU) Data Structure: DSU is important and used in Kruskal’s Minimum Spanning Tree Algorithm and in a bunch of other problems. I have encountered questions on DSU in a few coding tests including that of AB InBev.
- Trie Data Structure : Tries can come in handy in specific sets of problems on strings and bits. I was asked to implement a “set” for strings with O(n) or O(logn) complexity in my coding interview. You can do the same using Tries.
- Concepts of Object Oriented Programming (OOP): You should understand the OOP concepts like Encapsulation and Interface. Questions on OOPs in general and OOPs in C++ are often asked in coding tests in the form of MCQs.
- Regular Expression (regex): I encountered one question on regex in my entire placement (Trexquant). So it’s not important but if you have time, you may give it a shot in case you get unlucky.
Section 5 (not important for Placement tests)
I am adding this section to include height-balanced binary trees and string-matching algorithms. Because they are generally taught in algorithms courses.
But, they are not important for placement tests for all those companies that are open to non-CSE students. Most of the programming languages offer built-in implementation of pattern matching for strings. And, questions on height-balanced binary trees are generally time-consuming.
- [MIT 6.006] Lec.6: AVL Trees, AVL Sort (height-balanced binary trees)
- [MIT 6.046J / 18.410J Fall 2005] Lec.10: Red-black Trees, Rotations, Insertions, Deletions (height-balanced binary trees)
- [MIT 6.006] Lec.9: Table Doubling, Karp-Rabin (only Rabin-Karp part) (for pattern matching in strings)
- You can read about KMP Algorithm from GeeksforGeeks (for pattern matching in strings)
Section 6 (FAQs)
Q1. Is STL allowed in C++ in placement tests?
Yes, you can import all the basic libraries using #include . But, if the question asks to implement certain functionality already provided by a built-in function, then the placement organizer may block the usage of that particular function.
Q2. Can libraries be imported in Python in placement tests?
Yes, you can import any library you want. But the organizer can limit your options in questions on Data Analysis like in the Publicis Sapient Data Science profile. As a rule of thumb, put the usage of libraries to a least.
Q3. Is there any downside to using Python given that Python takes more time than C/C++?
No, the time limits to solutions are language specific. In general, only the complexity like O(logn) affects the acceptance of your code. But, note that this time Walmart put an absolute time limit on questions, likely a mistake from their side. An O(nlogn) solution didn’t get accepted in C++ or Python but an O(n²) solution got accepted in C. This was a rare incident and there isn’t anything that you can do in such situations.
Q4. Are we asked to solve programming questions in placement Interviews?
It depends on the interviewer. Some companies like Amazon asks to write proper code, (not pseudo-code) on paper. You need to practice writing code on paper beforehand. For other companies, the interviewer can either ask you to write proper code or pseudo code or may not ask a programming question at all. In such cases, your interview may revolve around your resume and other Aptitude questions/Puzzles.
Q5. Is OOPs important for placements?
OOPs is not important for coding tests and you won’t need to write classes or use inheritance etc. But, OOPs is important for MCQs in coding tests. Some companies have a joint MCQ & Coding test like Amazon. Also, OOPs is very important for interviews.
Q6. Is it important to have software internships/experience to bag a placement in software engineering?
No, except for the walk-in interviews and cases when companies go for a resume-based shortlist (generally happens after Day 2). The only thing that is important is your coding test. I didn’t have any software experience myself and only had an ML internship. So my interview went around my ML project. In your case, it could revolve around your resume. Even so, having an experience in software is always a plus.
Q7. How much CGPA and CV matter for placements?
There’s no straightforward answer to this question. I would try to answer this question from the perspective of the timeline of events in a job process for non-core software/ML profiles. First of all, companies open up and they put a general or department-wise cutoff. 7+ in most cases but higher in a few cases like Wells Fargo put 8.5+ for Mechanical Engineering. That’s where CGPA matters. After that, you give your coding tests and companies shortlist you based on your coding test performance. There may be 1–2 exceptions where the company also take into consideration your resume. So CV might play a role in 1–2 cases. After that, you go for your interviews and in most cases, only your performance affects your selection. There could be a few exceptions depending on factors like interviewer, profile and fellow candidates. So, your coding skills and performance in interviews (both technical and HR) are most important. Other things in general only help in clearing cutoffs. Even so, a good CGPA and CV are always a plus.
That’s it. If you have come this far, you should have gained excellent coding skills. All the best for your placements/coding challenges.
I have covered pretty much everything. I will update this post if I find anything missing. Thank You for reading and let me know in the comments about your experience in learning coding. If you liked reading this article, give me some claps.
Resources
Some other resources that you may find helpful:
- GeeksforGeeks: A wonderful website for all the theories and explanations of different solutions to various programming questions. GeeksforGeeks would be your Handbook for coding.
- [BOOK] Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein: For theory and a better understanding of any specific topic in Algorithms.
- Stack Overflow: For doubts or clarifications in programming questions/algorithms/your code.
- Lecture Notes of MIT Introduction to C++: In case you choose to learn C++, lecture notes of this course might be helpful. It’s not necessary to complete the whole course, only read the lecture notes.
- CS21003 Course by Prof. Abhijit Das, CSE Dept. IIT Kharagpur: For checking the proper syllabus of this course.
- Lectures Notes for CS21003 Course: Credits: Anubhav Jain, Student CSE Dept. IIT Kharagpur
Edits
Someday
- Corrected some linguistic mistakes and added more clarifications at certain points.
- Added Top 100 liked questions of LeetCode in the last Note of Section 1.
12-Feb-2020
- Corrected some linguistic mistakes and made some points clearer.
- Moved the OOP section from Resources to Section 4.
- Added GeeksforGeeks in the Resources section.
- Added some points in the section of ‘Programming Language’ to help choose between Python and C++.
10-March-2020
- Added a few images to balance the wordiness of the post.
17-May-2020
- Added resource for theory of Hashing in Data Structures in Section 1 (first Note there).
- Added 3 lectures (№2:Recursion Trees, №5:Recursive Thinking, №11:Matrix Multiplication and Master Theorem) in Algorithms of section 1.
- Added 1 lecture for Greedy Algorithms (№4) in Section 2.
- Added 3 lectures (№5:Minimum Spanning Tree, №8:Bellman Ford, №9:Floyd Warshal Algorithm) in Section 3.
- Added Section 5 for certain topics/algorithms that are generally taught in algorithms courses but are NOT important for placement tests.
- Added CS21003 website in the Resources section.
- Added CS21003 course notes of Anubhav Jain, student CSE Dept. IIT Kharagpur.
18-May-2020
- Shifted the Edits section after the Resources section.
- Changed some images and a bit of face-lift. No change in content.
- Added Regular Expression (regex) in Section 4 (Point №6).
22-May-2020
- Added missing link to lecture on Bellman-Ford (№8) in Section 3
02-July-2020
- Corrected some linguistic mistakes.
- Added some explanation at the start of Section 4.
23-July-2020
- Added Section 6 for FAQs (added Q.1, Q.2, Q.3) about placement tests and placement Interviews that I often encounter on various forums. I will keep adding relevant questions here.
- Added the following Note before Section 1: “ Note : Please note that I keep editing this article to best add all the relevant information/resources. I maintain a history of all the edits that I make so that it is easy for you to follow the changes if you are revisiting this article. So in such a case, please check out the Edits Section at the end of this post to check if anything is added after you last visited the article.”
24-July-2020
- Added Q.4 in Section 6.
- Added GeeksforGeeks link to Floyd Warshall Algorithm (Lecture 9) in Section 3.
- Edited solution of Q.2 in Section 6 to include libraries (heapq, collections, random and bisect) that are generally imported in Python for CP problems.
10-Sep-2020
- Italicized all the notes to differentiate them from the text. No change in content.
- Moved the note in Section 1: A) Programming Language from middle to end. No change in Content.
- Stripped down answers to Q.2 and Q.3 in Section 6 : FAQs
08-Oct-2020
- Added Q.5, Q.6 and Q.7 in Section 6: FAQs
25–July-2023
- Improved the writing w.r.t. Hemingway Editor. Re-worded the article, with no material changes.
Top comments (0)