5 Common Mistakes Made By Beginners Who Are Learning to Code.

Swapnil Baad
The Startup
Published in
6 min readSep 5, 2020
Photo by Ben Kolde on Unsplash

When I started on learning how to code I also was struggling to come up with an algorithm to solve it and I didn’t even know how to start. I often thought that this was not my piece of cake. In the following article I will tell you why you may be struggling to crack a problem that I myself faced when I started to code and now as a Professional Software Engineer have seen people why they give up too easily on finding a solution.

1. Getting Help

No matter how hard is the problem, don’t get help !!. Try out different approach or see the problem again and try to understand it. This may seem contrary to giving advice but once you try to solve problems on your own this will boost your confidence and you will have an arsenal of weapons which you can use to solve different problems. So as you solve more problems on your own you will get motivated and will accept a harder challenge to solve next time. If you get help and get the solution without ever thinking about it, the solution will only give you solace and next time when you solve a different problem and get stuck you will have a temptation to seek help. You will be less interested in solving a new problem as you know that you were not able to solve the prior one or were able to solve only a handful that you ever tried.

I am not saying that you should never get help, instead give your 100% in solving problem and assume that there is nobody that is going to help you. In this way, you will be a good coder in no time.

2. Sticking to only one solution

Suppose you started out with a potential solution using Arrays but the solution using arrays is too complicated, then you can try using for example dictionaries, HashMaps, etc. or you can use a different approach using arrays also. The important thing is to be aware while working out with algorithm is that whether your algorithm is getting complex and while coding it will get even tougher. One way is to ask yourself this question even if you have a solution. Can I do better?

Problem

Write a program to check it given string is “Palindromable”or not.

What is a “Plaindromable” string?

Let’s say you are given a string. You can get many strings (combination) out of the given original string if you rearrange characters of original string.

String is “Palindromable” if any one combination is palindrome.

Example 1:

Original String: NINIT

Combinations: NINIT, NNIIT, IINNT,ININT, IITNN, NITIN, INTIN, INTNI, NTNII, NNTII and so on

Original string is Palindromable because two palindrome can be made out of it.

Example 2:

Original String: NINNIT

Combinations: NINITN, NNINIT, IINNNT, INNINT, INITNN, NNITIN, INTNIN, INTNIN, NTNINI, NNTINI and so on

Original string is NOT Palindromable because NO palindrome can be made out of it.

Pseudo Code for first solution using HashSet

function palindromable(String inputString)    Create a character HashSet charSet    Convert inputString to character Array strArray using  toCharArray    for each character 'c' in strArray        if 'c' is present in charSet            Remove 'c' from charSet        else            Add 'c' to charSet        End of if    End of loop    if charSet size is greater than 1        // if there is odd number of occurence for more than 1 character

return false
else return true End of loopEnd of function

Pseudo code for 2nd Solution using Array

function isPalindrome(String inputString)Create a tempArray for storing single occurences of the characters in inputStringintialize index to zerointialize count to zerointialize oddcount to zerointialize flag to falseConvert inputString to character Array strArray using toCharArrayif strArray length is equal to one    return trueEnd of iffor each character 'c' in strArray   for each character 'j' in tempArray       if 'c' is equal to 'j'          set flag to true          break       End of if    End of loop    if flag is equal to false        set count to zero    for each character 'k' in strArray        if 'c' is equal to 'k'        increment count by 1    End of loop    if count divided by 2 does not give remainder 0        increment oddcount by 1    End of if    if count divided by 2 does not give remainder 0 and    length of the string is a multiple of 2        return false    End of if    if count divided by 2 does not give remainder 0 and    length of the string is not a multiple of 2       if oddcount is greater than 1          return false       End of if    End of if    tempArray[index] = 'c'    increment index by 1End of loopreturn trueEnd of function

You can clearly figure out First Solution is much more efficient than the Second Solution without getting into the time complexity of both of these algorithms, also you’ll require much more time to come up with the second algorithm. Even if you have a solution or you get a feeling that this algorithm will get more complicated then ask yourself, Can I do better?

3. Don’t know how to debug

Debugging the Code
Debugging the code for the above problem using first Solution

Let me tell you I didn’t use debuggers for a long time, it feels complicated to use but it has many perks. Once you start using debugger you’ll know where the mistake is and what exactly it is, in your code sooner. When you use IDEs for example of VSCode, Eclipse for coding, they have debugger tools. Most of the time new programmers don’t use these debuggers. One mistake you might be doing is to just see the output and getting stuck because you don’t see the right result/output and don’t know what to do next.

So next time you think that your code is not working properly then remember to debug. By using breakpoints and analyzing the values in the variables and also the state of the object you can easily find out what part of the algorithm needs to be changed, this can save you a lot of time and you can be more efficient. So first learn how to debug on your IDE.

4. Start coding straight away

This is by far the most mistake beginners do. When you are trying to solve a problem don’t just directly jump into coding. Take a pen and paper and figure out the solution instead of just hitting the keyboard directly. This will save you a lot of time because your logic would be more clear and you’ll make fewer mistakes while coding.

You can follow the steps below to develop an algorithm.

Step 1. Work an example for yourself.

Step 2. Write down what you did.

Step 3. Generalize steps.

From the above steps, you’ll get the pseudo code for your algorithm. The next step is coding! If you follow these steps you’ll arrive at the solution very much early. Or you don’t even have to follow these specific steps, when you see a problem forget about coding and syntax, just think logically and come up with a simple solution for example maybe brute-force approach then build and improvise your algorithm.

When you have an algorithm at your hand remember to evaluate your algorithm’s time/space complexity and ask Can I do better?

5. Not solving enough

There are many resources on the internet that you can make use of to level up your coding game. Pump up your brain muscles by solving more and more problems and trying out different solutions for the same problem this way in job interviews you’ll never be nervous about not being able to come up with an algorithm. You’ll know just by seeing the problem which data structures to use and which programming approach to use. You’ll be confident that whichever problem the interviewer will throw at me, I can find a solution.

Following are some of the resources that you can make use of to level up your coding game.

--

--