Texas Instrument hackearth question

Ques:
You are given a string S of length N consisting of digits 1 and 2. A string is considered as good if you can start at index f and reach index N, visiting each index exactly once and ending at the last index. At each index, you can move 1 or 2 steps to the left or right depending on whether the digit is for 2.
In this some test cases are failing can anybody tell where i am going wrong?

#include<stdio.h>
#include<stdbool.h>
#include<malloc.h>
char* solve (int N, char* S) {
   // Write your code here
   bool arr[N];
   for(int i=0;i<N;i++)
   arr[i]=false;
   int i=0;
   while(i<N)
   {
       arr[i]=true;
       char c = S[i];
       if(c==2)
       i=i+2;
       else
       {
           if(!arr[i-1])
           i=i-1;
           else
           {
               i=i+1;
           }
       }
   }
   for(int i=0;i<N;i++)
   {
      if(!arr[i])
      {
          return “NO”;
      }
   }
   return “YES”;
}
int main() {
    int T;
    scanf(%d”, &T);
    for(int t_i = 0; t_i < T; t_i++)
    {
        int N;
        scanf(%d”, &N);
        char* S = (char*)malloc((N+5) * sizeof(char));
        scanf(“\n%[^\n]s”, S);
        char* out_ = solve(N, S);
        printf(%s”, out_);
        printf(“\n”);
    }
}









Comments (2)