Please tell m what is the problem with my code

Please tell m what is the problem with my code. I am always getting WA. But answers are coming correct with test cases and even random values.

Question Link: https://www.codechef.com/problems/CHEFZOT

My Code:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    // your code goes here
    int n, count = 0, max = 0;
    // 	cin>>t;
    // 	for(int i=0;i<t;i++){
    cin >> n;
    int ar;
    // vector<int> arr;
    for (int j = 0; j < n; j++)
    {
        cin >> ar;
        if (ar == 0)
        {
            if (count > max)
            {
                max = count;
            }
            count = 0;
        }
        else
        {
            count++;
        }
    }
    // std::sort(arr.begin(), arr.end(), std::greater<>());
    cout << max << endl;
    // 	}
    return 0;
}

Check the following update to your code.

Accepted