Easy C++ Program


#1

"vector<vector > Solution::diagonal(vector<vector > &A) {
//upertriangular
vector<vector> ans;

int n = A.size();

for(int i =0; i <n; i++)
{
    vector<int> v;
    
    int col = i, row = 0;
    while(col >= 0)
    {
        v.push_back(A[row][col]);
        row++;
        col--;
    }
    ans.push_back(v);
}

for(int i = 1; i< n; i++)
{
    
    vector<int> v;
    
    int row = i, col = n-1;
    while(row <= n-1)
    {
        v.push_back(A[row][col]);
        row++;
        col--;
    }
    ans.push_back(v);
}

return ans;

}
"