Problem 12 of Arrays with custom solution