Added code for the 3rd queston