Adding solution to Question 1.1, without extra data structure