WA in Same Snake.

WA in SNAKEEAT

Here, is my code for SNAKEEAT. It passed the given test case and was working fine for all the test cases I tried. Here is the link to my code. Could please help me debug it? Thanks.

Try this case:

1

4 2

1 1 1 1

1

2

Your Output:

7

2

Expected Output:

4

2

Your code fails in cases where all the lengths are same which is creating problems in counting total possible snakes at line
int snakesLeft = index; max_snakes_possible += num_of_snakes - index;

and so in the while loop you’ve used.

You're using Lower Bound in binary search for similar elements, if you handle it your problem would be solved. 

Other case to check

1 

2 1

1 1

1

Your output: 

5

Expected Output:

2

Hope that helps!!
2 Likes
//