Solution for problem 2 using Lambda (Java 8)