Getting wrong answer

my sol–https://ide.codingblocks.com/s/379000

question–https://www.codechef.com/NOV20B/problems/FEMA2

please tell me why i am getting wrong answer i also watched editorial i am not able to understand, i approached this question my self but getting wrong answer. please tell me what wrong i am doing in my code i am very confused

Hey @shivamgoel150
Your logic is missing this type of cases

4 5
MMII
Here u will consider M & I but u are also skipping a possible pair
So for that just remove
i=j statements from ur code

Here is ur updated code https://ide.codingblocks.com/s/379014

sir can you please explain me why to remove i=j when i am encountering “X”

I just removed all i=j to consider all cases
Try adding it if it gives WA then I will try to think of a case for that :slight_smile:

sir i tried to add but its giving wrong answer i am started confusing again

Okay so I found a testcase on which it will fail if we keep them

6 1
M_:IMX