HELP ME FAST

THIS IS THE QUESTION LINK
CLICK HERE

THIS IS MY ANSWER LINK
CLICK HERE

I DONT KNOW WHAT IS THE ERROR BZ THE PROGRAM IS WORKING FOR GIVEN TEST CASES AND ALSO OTHER CASES
CAN ANYONE CORRECT MY CODE AND SEND…

Why there are so many loops there… -_- and two loops have same variable j too… one for loop should be sufficient… https://www.codechef.com/viewsolution/14389395

1 Like

The j variable gets overwritten within the second loop…

Also, this can be simplified into 3 steps…

  1. count the numbers with value of -1 (assign, for example, n_one)
  2. count the numbers with value of 1 (p_one)
  3. count the numbers with absolute value greater than 1 (others)
    Then, you just need to check for some cases.
    See this

(https://www.codechef.com/viewsolution/14732502) for more clarification (just check the comments, you can ignore the codes).
1 Like