plz check where i am getting wa I have tried with test cases given in comments I have used those test cases as input in the ideone link above. TIA