Simple C++ solution with explaination!


As, we can observe here that for every index where i+j is same belongs to same new vector in output array. also, the size of output array is an AP, for which the general term is calculated as above.
So, here is simple code implementation for the same.

vector<vector<int> > Solution::diagonal(vector<vector<int> > &A) {
    int n=A.size();
    if(n==0) return {};
    vector<vector<int>> v(2*n-1);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
    return v;


(lower limit is 20 letters to comment…so i m still typing)