Problem 14 of array with custom solution