made second solution using the recommended hash of arrays