Piyush and Magical Park

please help me with my code

Neerav, plz use these conditions as well in your code ,

      else
    if(ar[i][j]=='#')
    {
      N=N+1;  // for next row
    }
    else
    if(ar[i][j]=='#' && i==N-1)
    {
      break;   // if that is last row
    }