whats wrong with my code..its is showing wrong answer??


As an example of input that gives a wrong answer:


should give answer of 2; your code reports 1.

Thnanks…i was unable to find out.

This means I need to change the whole logic???right?

Yes, probably you do need to change your method.