Solved using two while loop ,Easy solution


#1

vector<vector > Solution::diagonal(vector<vector > &A)
{
int n=A.size();
vector<vector>res;
vectorv;
int i=0;
int j=0;
v.push_back(A[i][j]);
res.push_back(v);
v.clear();

while(j!=n-1)
{
    int col=j+1;
    int row=0;
    while(row!=j+2&&col!=-1)
    {
        v.push_back(A[row][col]);
        row++;
        col--;
    }
    res.push_back(v);
    v.clear();
    j++;
}
while(i!=n-1)
{
    int col=n-1;
    int row=i+1;
    while(row!=n&&col!=i)
    {
        v.push_back(A[row][col]);
        row++;
        col--;
    }
    res.push_back(v);
    v.clear();
    i++;
}
return res;

}