Add solution to problem #42

Added solution to problem #42