https://www.codechef.com/problems/XYSTR problem in beginner " chef and string question"

https://www.codechef.com/problems/XYSTR : problem
https://www.codechef.com/viewsolution/34671991 : my solution

the logic i used: after the user enters the string, i found the length of string using strlen().
then i checked every element with its next element and checked if it was a pair or not.
if it was a pair, i increemented count by 1 and also incremented loop counter by 1 so that the next element does not get checked again since it has already formed a pair with its previous element.
this code was like:
for(i=0;i<l-1;i++)
{
if(arr[i]==‘x’ && arr[i+1]==‘y’)
{
count++;
i++;
}
else if(arr[i]==‘y’ && arr[i+1]== ‘x’)
{
count++;
i++;
}

    }

note: the codechef ide gave incorrect answers but when i ran it on my codeblocks (using gnu compiler) i got correct answers.
thank you for your help :slight_smile:
and sorry if i am missing something obvious :sweat_smile: