A strategy to crack almost all coding questions in a timeframe

How to crack Programming/Coding exams

Amal Shaji
6 min readMay 22, 2021

Programming/Coding competitions are not new to us. If you are a programmer it might be part of your daily activities and if you are a student/jobseeker you may encounter it in your exams, preliminary tests, and even in some cases, interviews. Even with its wide use cases, there are no proper strategies/methods to handle these questions. Also, the books in this regard are little to None. In this article, I’m trying to address the above scenario and explain a strategy that I have tested in multiple competitions and got results.
Let’s start with a scenario. It has been your lifelong wish to work in X company. Your CV is accepted and you are invited for the preliminary tests which will have a direct selection to interviews. It is the day of the test. You believe you have prepared enough. You are strong in a programming language and that gives you an enormous boost in confidence. The exam has started you can see the coding question on the screen in front of you. To your bad, there is a timer next to it which counts from 30:00 mins. You are aware of this but not concerned. After all, a person of your skillset will take at most 20 mins to solve such a question.

You started reading the question. It took a nice 2 mins read to complete the question. You are confused, you haven’t understood the question. You again go through each line taking more time. You have a vague idea now. Suddenly a ray of hope glimpses through your face. A slight smile accompanies. An idea, a way which can be used to solve this question, you have it now. For the next 10 mins, the loud key clicks of the pretty old desktop computer arise. You’ve completed the program now. It is in the compilation phase. Suddenly red lines of text pop up.

You are not tensed. You expected this already, errors. After another couple of minutes, everything is rectified, all syntaxes have been corrected. The timer is approaching the end. It’s time to get your fruit. The result for your hard work, not only for this 30 mins but also for the past couple of weeks. You click on Run. Almost instantly you get the message, 3 test cases have passed. To your disbelief rest of the 2 private test cases have failed.
Whatttttt……………………………… The sudden wrinkles in your forehead tell it all.
Have I done a logical error, which are the test cases that are failed, should I change the logic and redo the program? Before finishing your thoughts, the final message appears.

This had happened to me and was the inspiration to come up with the strategy/method which I’m going to explain below. Let’s start with analyzing the most important factors that affect our efficiency/performance in such situations. The biggest factor is time as you have guessed already, then the experience of handling such questions before, and lastly knowledge in the programming language. You might be thinking of other factors but all are divided from these three basic factors. So our strategy also will be for efficiently handling the above three factors.

The Strategy:

There are 2 parts to this strategy, the first part is preparing for the exam and the second is how to attempt the question itself

Preparation for the exam:
This is the stage where you have to analyze the exam syllabus and pattern. If there are specific topics mentioned, we have to look into each topic separately.
The key is practice, there is no luck involved. You have to do more and more coding questions. The more the better. In this phase, you have to analyze the complexity of the exam. For this, you can use previous years’ questions. Once you have the complexity you can practice similar complexity level questions using online coding sites. My favorite is Codewars, where you can choose the complexity level and attempt the questions accordingly. You should only attempt the questions of the required level and the ones under that. Never attempt questions with more level than the complexity of the exam, this is because it is a waste of time, energy, and demotivating.
You should be mastered at least in any one of the programming languages and also well versed with data structures and common algorithms in use. If you have more time you can refer to various books available on this topic. “Introduction to Algorithms, TH Cormen, CE Leiserson, RL Rivest, C Stein, Third Ed, 2009, PHI” is my favorite.
As I said earlier the motive is to gain maximum practice. If you have worked enough you will reach a stage where you can relate new questions to the ones you have solved before and reuse the logic. Believe me all these counts on the exam day.

How to attempt the questions:
This I feel counts more to your success than the above step. No matter how hard you worked it all leads to this point in time, the exam hours. You have to divide your answering process into 5 parts. Each part is important and you have to fix the at-most time for each part. This is also applicable when you are practicing.

  • Understanding the question.
  • Creating an algorithm.
  • Taking care of corner cases.
  • Coding in your favorite language.
  • Error rectification and modifications.

Let’s explain the parts with the Scenario I mentioned at the beginning itself. The exam is 30 mins in total. So I fix the first 3–5 mins to properly understand the question. This includes understanding the question, the type in which inputs are given, and also how the output is expected. Once you have a clear idea of the question you can move to the second and third steps. These should be done together. From the practice and knowledge, you have, try to come up with an efficient algorithm to solve the issue. (Tip from exp: If you have to write more lines of code to solve a problem, that usually means there is an easier way around and you have to search for it). Once you fix the algorithm quickly search for the corner cases, such as where the loop end, is it n or n-1. Or what happens when 0 comes in your input etc… If the corner cases are too much, change the logic/algorithm immediately and redo steps 2 and step3. Once steps 2 and 3 are done and the algorithm/logic is fixed then you shouldn’t change it. All these steps will take like 10–15 mins of your 30mins. Rest 15 mins you have to code the same and check for syntax errors. If all the steps went smoothly you will get the message, all test cases passed.

Congrats. The hard work has paid off. Even if you fail you can be happy that you have tried and attempt again with more preparation. Good luck to all pioneers out there.

With regards,
Amal Shaji

--

--