Question is not clear i hope it will help


#1

int Solution::solve(vector<vector > &A) {

int n=A.size();
if(n==0)
return true;
 int m=A[0].size();
 
   vector<vector<bool>>dp(n,vector(m,false));
   dp[0][0]=true;
     for(int i=1;i<m;i++)
     {
          if(A[0][i]>A[0][i-1] and dp[0][i-1])
            dp[0][i]=true;
     }
     for(int i=1;i<n;i++)
     {
         if(A[i][0]>A[i-1][0] and dp[i-1][0])
         dp[i][0]=true;
     }
   
     for(int i=1;i<n;i++)
     {
          for(int j=1;j<m;j++)
          {
              
              if((A[i-1][j]<A[i][j] and dp[i-1][j])||(A[i][j-1]<A[i][j] and dp[i][j-1]))
                dp[i][j]=true;
          }
     }
     
     if(dp[n-1][m-1])
     return n+m-1;
      return -1;

}