Giving correct answer for sample input but not passing the testcases?