i am getting the wrong answer but my output is right

Thanks a lot sir you helped me a lot.

Just do this

scanf("%d",&n);
int arr[n]

and your array would be ready.

Just a question if i have to make a if else statement if someone gives input other than 1 and 0

Well yeah, you could do that, but that’s just overkill. Be assured that there won’t be any inputs other than 0 , 1 . Unless it is mentioned specifically in the question, illegal inputs won’t be present in competitions.

So, did you solve it finally?

new error is encountered called time exceeded
solution https://www.codechef.com/viewsolution/22077657

It’s because you are using the same variable i for all the for loops which is messing up the conditions leading to TLE. Use different variables for each for loop.

did it sir finally ,it won’t happen if you didn’t helped me
if had to ask you in future directly how can i ask?

solution of right code https://www.codechef.com/viewsolution/22077831

Well, you can mail me at [email protected]

And yeah, I’d suggest you to improve upon the basics of implementation and input/output before jumping on to solving questions from contests. Good luck!

thank you sir but can you please tell me how can i improve it so that i can work with it

I started coding on GeeksForGeeks first. It has well written solutions of all the problems along with proper comments and formatting. If you wish, you could learn the coding style from there.

All this is based on personal experience and if you wanna improve your basics from CodeChef, it’ s fine too.