Posts tagged with: algorithms


Another (iterative) technique for enumerating permutations

The idea of writing this post came up by reading Programming Interview Questions 11: All Permutations of String by Arden Dertat. The author proposes a simple and elegant recursive algorithm that finds all the permutations of a given string.

If any of you is interested in an alternative (iterative) solution, here is one. I think it has a couple of features you may find interesting.

The starting point is to define an order among all the permutations and then write a procedure that, given a permutation, returns the following one. The order is simply the lexicographic order and the procedure is the following. Read more...

Tags: algorithms, cpp

Codility Challenge “Argon 2015” solution

Codility might not be the best way to assess a candidate (especially if it is the only one!), but there is definitely something in it that I like. The idea of my solution to a programming task being automatically evaluated after I deem it ready is not unfair—after all, programs are run by machines and have to be correct, efficient (more or less, depending on the context), and handle corner cases.

But the thing I like most of Codility are, of course, the challenges. I find them both difficult (I envy those who can solve them in 15 minutes at the first attempt) and fun. For me they are more workable than Project Euler’s problems, which are indeed interesting but difficult to understand if you don’t hold a degree in mathematics.

Good solutions for Codility challenges are not easy to find, and when you find one, in most cases it’s a huge blob of code with no explanation. Let’s try to solve Argon 2015 step by step. Read more...

Fork me on GitHub