Problem 8 of array with custom solution