Let’s get back to college and the great Algorithms and Data Structures course. That’s one of the most fundamental Computer Science courses, which develops the analytical and problem solving skills of the students. Apart from that, it’s also very addictive and great for learning new programming languages and concepts.
Recruiters also like to use them as a first evaluation of the technical skills of the job candidates. Unfortunately, in the industry, you don’t often get the chance to use most of these algorithms – although probably that’s not the case with the big tech companies solving large problems for millions of users. Therefore, as the time goes by, we tend to become a bit rusty in this skill, so I’ve decided to get a refresher in Algorithms by tackling the Codility training centre problems. And there’s no better way of doing this than with Swift. Even if you think you are already a pro at Swift, you might get surprised by the new things you get to learn by solving these problems.
The problems are nicely split into sections, where each section first contains a PDF document explaining the basic concepts that you need to understand in order to solve the few tasks that go with it. The tasks are split into three levels – painless (which should be solved by most of the software engineers), respectable (which are harder and might get you stuck for a while) and ambitious ( for the ambitious ones 🙂 ).
There are some things that are repeating throughout the tasks, like all the different iterations (with index / value), both starting from the begining of the arrays and from the end. For example, I didn’t know how to loop through an array backwards in Swift (reverse and stride, anyone?). Then, it’s also nice to know how to convert a number to a binary string, how to write a simple Stack in Swift and so on.
I highly recommend tackling the tasks by yourself first, not looking at the solutions directly. In any case, you can find them here. Any feedback, new and better ideas on how to solve the tasks are more than welcome. Enjoy.