Solving Coding Challenges

            Being presented with an algorithm or whiteboarding problem can be daunting and is part of most software engineering interviews. It can be extremely challenging to solve a coding challenge on the fly where you have tons of pressure and you feel like you do not have time to think but there are a few steps and strategies to help solve any coding challenge presented to you. Disclaimer like most these blogs I am no where close to an expert and this is mostly and excuse to help myself by compiling information in one easy place.

Understand the Problem

It might seem obvious but the number of times I have been too eager to start the challenge and miss an important part of the question and end up going down the wrong path or missing an edge case. Before diving in make sure you have thoroughly and correctly read or heard the question. Reread the question write down the question

if prompted verbally so you have something to go back to while writing the solution. Ask question if needed not one will doc points off for clarify quite the contrary from my understanding one of the biggest purposes of a whiteboarding interview is not to make sure you are some coding genius who can solve the presented problem in two minutes without asking a single question. They want to see what your problem-solving process is like and on some level how you collaborate. Make sure to take the time to clearly understand the problem and write down examples, input, output and so on. This will start to get your brain flowing on possible solutions.

Break down the Problem

This also might go hand in hand with understanding the problem but sometimes you get started on a problem and realize you have thought about the solution at too high of a level didn’t break the problem down it to small solvable chunks. This can lead to backtracking and rewriting code which is a waste of time. You must break down the problem into smaller and easier version of the overall problem or subproblem. This will allow you to further understand the problem while allowing you to start planning functions and data structures to use along with this if the problem ends up being beyond your skill level you have something to show for your effort as you most likely solve some easier part of the overall question.

Choose a solution and Outline

For most coding challenges there is a lot of different ways you can solve one problem, but you must choose one for certain solutions its easier to do things recursively or with a hash. It can be difficult to know exactly how you want to solve it before but a good way to get started if you are stuck is to quickly solve the problem manually to derive the algorithm for the question, then solve the problem programmatically. Once you know the general direction of your solution you can work from there identify what helper functions, edge cases, terminating logic and data structures you will need to solve it.

Improve your code

Lastly, once you have found and coded a solution try to improve it, in whatever way you can. Ask yourself is there a simpler and more clear way to do this, can I make it more efficient,  did I miss something, would this this data structure benefit from being a different one. There are many ways to improve your code and chances are the code you just wrote on the fly could be improved, so be self-aware even though you don’t know how to improve it at least point out an area that you could improve.

Well I hope some of this was helpful best of luck to all on their coding challenges.

Leave a comment

Design a site like this with WordPress.com
Get started