Wrote the algorithm and added two more test cases