How To Improve Logic Building in Programming

Yout 13 step guide to building good problem-solving skills

Hari Sapna Nair
TheLeanProgrammer
6 min readApr 19, 2021

--

Most of us find it difficult to build logic while solving coding questions, especially during the initial days. We struggle to find the most optimized solution after solving it in the brute force method. And after every coding contest, we get disappointed and think of quitting.

In this blog, I will be sharing with you some tips to help you build logic while solving coding problems.

1. Choose a language

This is one of the common mistakes beginners make. They spend too much time selecting a language. They get confused as some of their friends might be learning python or the YouTuber they might be following will be teaching Java. At this stage, it’s better to select one language either CPP/Java as it is preferred by companies during interviews instead of wasting your time deciding the language. Also, don’t try to learn all the languages at once as you might get confused with the syntax.

2. Cover the theory before solving problems

Instead of jumping into the questions devote some time to clearing your concepts. Most of the coding question requires a proper understanding of data structures and algorithms. Also, learn the internal implementation of the functions and algorithms as in some scenarios it is not allowed to use inbuilt libraries.

3. Learn from successful submissions

After solving every coding question go through the top submissions. There are chances that we might find different ways to solve the problem which we might have not thought of before. We can also learn many ways of making our code faster techniques like by using Fast I/O in Java, or by using scanf in CPP by going through the code of these submissions. Also going through the editorial is very important.

4. Be Consistent

Our excitement to learn programming fades after a few days especially after having a bad performance in coding contests. During this time it is really important for us to maintain the momentum and not quit. If we quit at this stage, it will take us more effort to recollect the concepts we had learned before when we try to start again. Even in cases when we don’t feel like doing anything we should do at least one question or do a revision to maintain consistency. Remember it is a marathon, not a sprint. Prepare to run far, not fast.

5. Prepare notes

Keep a separate note for programming. When we encounter a new concept, trick, algorithm, or logic we should note it down so that we can revise it in the future. So try noting down the library functions as it will be helpful during the interviews where there won’t be any autocomplete feature. We can also note down the pseudo-code of algorithms like binary search, merge sort, etc along with the time complexity of each algorithm.

6.Pair Programming

It’s always better to do pair programming as together, you will be able to find different approaches for a particular problem. It also helps us to be committed as there will be healthy competition and it will help us perform more efficiently. By setting goals for each other we can benefit a lot from this approach.

7. Brute force to Optimized solution

When we approach a new question instead of finding the easiest solution we try to find an optimized solution. In most cases, the optimized solution is derived from the brute force approach. So instead of focusing on the optimized solution, we should try to solve it in the brute force method.

8. Coding Contest

Coding contests are a really good way to practice for interviews as we will get used to solving new questions in a limited time frame. But one should not rush into competitive programming. We might get demotivated and end up quitting.

It is perfectly ok if you are not able to solve the questions. Try to learn something from every coding contest. After every contest, try to solve the questions you were unable to solve. Ask your friends or read the editorials if you are unable to form the logic.

9. Move on

Don’t get stuck in any question for a long time. If you feel that you have tried your maximum just look at the hints and if you don’t know that concept read about it in some article. If you are unable to solve it after that try going through the pseudo-code or algorithm for the problem and code it.

10. Think before you code

Before starting to code we should spend some time thinking about the problem statement. After we understand the question properly, we should analyze the edge cases, try making our own test cases, etc. Break down the problem into sub-problem and use flow charts which will help you in writing the code.

11. Solve puzzles

Coding questions are a combination of simple maths and puzzles. Solving puzzles daily will help you keep your mind sharp.

12. Solve a random question daily

Try solving a question from a random topic as it will help you learn new concepts daily and revise the older ones. For this, you can practice in the monthly leetcode challenge where you will find questions on random topics daily.

13. Revise regularly

Many beginners make the mistake of not revising the concepts after learning them once. What happens is after a few days we forget it and we have to study it from scratch.

The learning curve will be at its peak only for an hour after you study. To retain the concepts for a long time keep an hour for revision every day. You can also practice questions on a specific topic every weekend so that you remain in touch with various concepts.

Platforms to practice coding questions

  1. Geeks For Geeks
  2. Leetcode
  3. HackerRank
  4. HackerEarth
  5. InterviewBit
  6. CodeChef
  7. CodeForces

There are several platforms available online and it’s not possible to do questions from every platform. Just try out all the platforms and choose one/two platforms and practice from them. If you are preparing for interviews, Interview bit will be the best choice as it has a limited no: of questions from every topic.

“Whenever you feel demotivated just think why you had started in the first place.”

Follow these tips seriously and become a pro at programming. That’s it from my side, I hope you found this post useful 😊.

If you want to get connected with me, please follow these links
Github-https://github.com/Sapna2001
LinkedIn-https://www.linkedin.com/in/sapna2001/
Website-https://sapna2001.github.io/Portfolio/
Quora-https://www.quora.com/profile/Sapna-191

And if you have any suggestions, feel free to get in touch with me over LinkedIn & the comment section is also all yours.

If you liked this story, hit the clap button as it motivates me to write more & better.

Thanks for reading!!!!

Don’t forget to follow The Lean Programmer Publication for more such articles, and subscribe to our newsletter tinyletter.com/TheLeanProgrammer

--

--