I am getting correct answer for the test case which i am giving.But here it shows WA.Can somebody please give me the case for which my code is not giving correct output.

Logic of my code:-
I have created two boolean arrays with setting the ith element as true where i is given as the the input. Now, for minimum steps, I check if ith number is alive and the three consecutives digits are present and if they are there then I kill all of these by setting them as false and increasing count by one.if there are only two consecutive numbers then I kill both of them and add count by one.

For maximum steps, i simply kills elements from first and deletes the consecutive digits if it is there.

my code:-CodeChef: Practical coding for everyone

same was the case with me :(. I am also facing the same issue.

My algorithm was a different, but I also got WA. I thought my algorithm was correct, and it worked for every test case I could think of. I grouped all the consecutive numbers together. Hence, I got some ‘n’ groups of consecutive numbers. The number of minimum or maximum steps for each group would be independent of other groups. I used PNC with these groups to get the correct answers (according to me). Could someone also please tell me the corner cases in this situation which I probably missed. Here’s my code:

Try this test case :




Your code gives output as : 0 0

1 Like

You have to sort the input array. Now take a boolean array, the ith element of which is true is the number i is alive or false if dead. For minimum steps, see if you can get 3 consetive elements in the sorted array. If so, make the three numbers in the boolean array false( kill the middle number) and increment your count by 1. After you have finished searching all the three consecutive numbers, search for 2 consecutive numbers, and if you get, make the 2 numbers false in the array and increment count by 1. Finally see how many elements of the boolean array are true and this number plus the count is your answer. For maximum steps, in the place where you killed the middle number in the boolean array, kill the first number and increment you count by 1. The remaining steps remain the same. My code: CodeChef: Practical coding for everyone