Adding solution to Question 1.1, with extra data structure