Check in the questions.
Some unit test cases for Question 1.
Basic solution to Question 1.