Error in one test case


#1

My Approach:

vector<vector > Solution::levelOrder(TreeNode* A) {
vector<vector> ans;
if(A==NULL)
return ans;
if(A->left==NULL && A->right==NULL)
{
vector v(1,A->val);
ans.push_back(v);
return ans;
}

queue<TreeNode*> q;
q.push(A);
q.push(NULL);
while(!q.empty())
{
    vector<int> v;
    while(q.front()!=NULL)
    {
        TreeNode *t=q.front();
        q.pop();
        v.push_back(t->val);
        if(t->left)
            q.push(t->left);
        if(t->right)
            q.push(t->right);
    }
    q.push(NULL);
    ans.push_back(v);
    while(q.front()==NULL)
        q.pop();
}
return ans;

}

Runtime Error. Your submission stopped because of a runtime error. ex: division by zero, array index out of bounds, uncaught exception You can try testing your code with custom input and try putting debug statements in your code.
Your submission encountered runtime error for the following input:
429 91 41 174 168 124 139 180 202 146 206 141 53 31 100 211 72 -1 109 213 -1 -1 169 181 162 132 108 75 23 30 131 99 36 35 -1 177 183 97 -1 184 4 113 157 118 186 143 78 147 197 80 -1 5 10 42 89 144 57 86 47 32 101 203 -1 163 21 63 136 150 -1 128 207 172 159 -1 127 214 73 1 51 -1 -1 152 111 48 196 166 142 39 -1 -1 -1 -1 11 46 15 6 13 194 22 126 176 104 179 198 93 49 175 195 188 82 134 -1 -1 112 130 92 -1 -1 -1 178 -1 -1 -1 -1 62 71 38 -1 -1 69 -1 -1 -1 20 8 -1 -1 -1 -1 103 -1 -1 54 67 -1 -1 -1 56 -1 -1 122 37 59 -1 125 120 -1 18 14 167 -1 43 158 154 77 204 -1 -1 -1 -1 170 94 25 160 107 2 -1 -1 -1 123 9 106 28 -1 -1 -1 -1 -1 44 165 -1 -1 -1 -1 76 -1 151 95 -1 -1 98 17 -1 -1 60 117 187 -1 -1 -1 -1 -1 173 -1 121 61 -1 -1 -1 -1 208 -1 119 140 -1 -1 -1 -1 -1 65 164 40 135 156 -1 -1 -1 105 -1 -1 -1 -1 84 149 -1 189 -1 115 85 190 133 -1 -1 116 192 209 3 182 -1 -1 -1 191 -1 205 7 102 -1 114 -1 148 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 138 88 -1 -1 -1 -1 -1 58 52 -1 -1 -1 -1 155 -1 24 -1 -1 -1 -1 16 50 -1 -1 -1 -1 -1 -1 -1 29 -1 -1 212 -1 -1 129 70 153 66 193 12 -1 -1 199 171 -1 96 -1 200 145 79 -1 -1 45 -1 -1 -1 -1 -1 110 -1 74 201 -1 -1 -1 -1 -1 19 27 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 33 -1 137 -1 -1 -1 -1 -1 -1 161 -1 81 26 210 -1 -1 87 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 90 -1 -1 -1 -1 -1 -1 -1 -1 -1 68 185 55 -1 -1 -1 -1 -1 64 -1 -1 -1 -1 83 -1 -1

Pls help!!