Loading...
New webinar: "The Remote Job Search: My Microverse Journey" with graduate Paul Rail
Watch Now

We have launched an English school for software developers. Practice speaking and lose your fear.

Topics

Coding challenges are absolutely crucial to your learning but can often be very difficult to solve. We've previously shared an article with the best websites and resources to practice with, and now we're focusing on some actionable overall advice.

Mastering algorithms and data structures can help you supercharge your coding challenge solutions and step ahead of your peers. That said, they take years of practice to master, so it’s easy to get stuck as a beginner. But, it is an essential skill every software developer should have, the importance being:

  • It improves your problem-solving skills as it helps you understand the logic behind everyday tools, and assists you in coming up with interesting ways of solving problems.
  • It helps you to learn some design paradigms like divide-and-conquer, dynamic programming, and the greedy method.
  • Oh! And you can also learn some really fun math skills.

However, most developers don’t focus much on this. If you happen to be among those who do - well, that’s probably why you are reading this - then these tips will help you become better at tackling coding problems.

Don't Rush 

Again, don’t rush - you’re not trying to catch a bus.

A lot of people jump right into coding without a proper understanding of the problem, then get stuck, rather than taking time to first understand the problem. Understanding the problem is the most important aspect of solving any coding challenge - and really, the most important part of solving any problem in life, as you can’t solve what you don’t understand. 

Once you understand the coding problem, try solving it on a piece of paper first. Don’t worry about the code, syntax, or efficiency just yet. Simply focus on this - can you solve it? If ‘yes’, then congratulations, you just increased your problem-solving skills by 10! If ‘no’, then continue staring at the paper until you’re able to solve it. 

While some might disagree, solving on paper saves you a lot of time and energy because it defines the structure of your code, and if you’re able to do it then, you will just have the code to worry about.

Break the Solution

When solving a problem, break things into smaller steps. This helps in building simple code, analyzing what makes it work, and discovering other solutions. Depending on the magnitude of the problem, you can create a solution to pass just one test case before considering other cases or the edge cases.

Let’s look at an example - the “Repeated String” challenge;

The challenge is to find and print the number of occurrences of the letter “a” in the first n letters of an infinite string.

{% code-block language="js" %}
def repeatedString(s, n)
end
{% code-block-end %}

s is the string to be repeated.

n is the number of characters to consider.

If we have a string ‘aba’ and n is 6 then the substring to consider will be ‘abaaba’. The letter “a” appears 4 times. 

This is quite easy to solve on paper but how can the computer solve it? Let’s break the solution into smaller steps:

  1. What will be our output? An Integer.
  2. How can we count the a’s in the string? Set a counter to 0 and iterate through the string and increase the counter if a is found.
  3. How can we find the number of times the string can repeat itself in n characters; Divide n by the length of the string s.
  4. How do we get the number of a’s in the repeated string? We simply multiply the number of a’s in the original string (step 2) and the number of times the string can repeat itself in n characters (step 3).
    Note: We set n as 6 because we have 3 characters in the string. This will ensure the string repeats itself without cutting off any character and makes it easier to solve. By doing this, we’re halfway to solving the challenge.
  5. How do we find the number of characters that are cut off? We use the modulo operation.
  6. How do we check if the remaining characters contain the letter a? We iterate through the remaining characters and add them to our counter if a is found.
  7. We return the counter.

There are likely better ways of solving this, but it’s an example of how to break down solutions.

Don't Look Up the Solution

It can be tempting to look up solutions to a challenge but this is bad practice. It’s bad practice as it’s easy to be constrained to thinking in a certain way after looking at the solution, so you have to resist - resist it like you do procrastination

In all seriousness, looking up the solution should be your last resort. If you must look it up, get a solution that has everything explained in detail, this will ensure you understand the logic behind the solution and you’re not just memorizing the code. Then, once you understand the logic, come up with a different solution. Your solution might not be as effective as the one you saw but this process will improve your problem-solving skills.

Efficiency

No amount of hardware is going to compensate for an inefficient algorithm.  

Examine your solution carefully; this is where you should pay attention to time and space complexity. The explanation for that is beyond the scope of this article but you can read more about it in this article

When looking at your solution; can you replace that “sort” method? Can you remove the nested loop? LeetCode is a good place to check the time and space complexity of your code, I remember shaving off milliseconds from my code by replacing the sort method. This might not sound much, but a few milliseconds is equivalent to three years in the coding world -- that’s an exaggeration but I hope you get the point.

Practice

Practice makes perfect... The more coding challenges you do, the better you become at them. Start with the easy ones and move your way up. Then come back to the challenges you’ve completed and try to solve them differently or solve similar challenges. 

Remember, everything takes time, don’t beat yourself up if you can’t solve a challenge! 

I hope this helped you understand how you can improve at coding challenges…. happy coding!

Photo by Siz Islam on Unsplash

We have launched an English school for software developers. Practice speaking and lose your fear.

Subscribe to our Newsletter

Get Our Insights in Your Inbox

Career advice, the latest coding trends and languages, and insights on how to land a remote job in tech, straight to your inbox.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
We use own and third party cookies to; provide essential functionality, analyze website usages, personalize content, improve website security, support third-party integrations and/or for marketing and advertising purposes.

By using our website, you consent to the use of these cookies as described above. You can get more information, or learn how to change the settings, in our Cookies Policy. However, please note that disabling certain cookies may impact the functionality and user experience of our website.

You can accept all cookies by clicking the "Accept" button or configure them or refuse their use by clicking HERE.