I tried to implement code for SNCKPB17/SNELECT, below is the link to it. Can anyone please give me a test case where my code fails? I’m not able to find any such test case though I it got wrong when submitting it.
Final configuration after eating will be: mmmmmssssss
Expected output : Snakes.
Your output : Tie.
The error happens as (considering 1 indexing) both of ur mongooese number 1 and 3 are eating snake number 2. Instead only one of them should eat it.
Try this test case-
Input 1 msmmssss Your Output mongooses Correct Output tie
I recommend try convering that ‘s’ to any other char like ‘*’ because i suspect your error is snakes getting reduced twice in case of “m s m” .
23 second difference b/w our answers. Nice eye mate XD
Your output: mongooses
Expected Output: tie
Actually your if condition is wrong. First you are checking if ith position has ‘m’ then you are checking if (i+1)th position has ‘s’. But suppose (i+2)th element is ‘m’ then for it, the first if will hold as (i+2-1)th position is ‘s’, which means (i+1)th position is considered twice.
To resolve this, just keep track of a Boolean visit array, and mark all the ‘s’ that are visited.