adding comment and functions skelton
Solved the function. and Added comments to explain how the function work