Comments

Yes I got it now. Thanks btw

The answer will be 0 for those cases.

I think even if you break the loop, the if statement below will take care of that.

You answer is failing on the 10th test case i.e for "3 3 1" your answer is 2 which I believe is correct as "1 3 2" and "2 3 1" are valid permutation. I don't know why they are showing 0 as output.

Can you tell me the answer for input "3 3 1", the output shown is 0 but "1 3 2" and "2 3 1" are valid permutations.

I think they have made some mistake. Since middle element can be found in a single step, "1 3 2" and "2 3 1" should be valid permutations.

Even if you break the loop, the if statement below will take care of that.

For input 3 3 1, answer should be 2.

The first question can be done in constant time using the fact that if n is odd then a=x, b=x-1 where x=floor(n/2) and if n is even and x is also even, then a=x-1 and b=x+1 and if n is even and x is odd then a=x-2 and b=x+2.

0

Same here. I solved 1st and 3rd question on paper within few minutes and when I clicked submit button after writing the code on their editor, connection failed and page could not reload for about an hour. After some time the issue resolved but after submitting solution of 1st question, same thing happened again