Approach # 2 implemented

Worked fine with my test cases.