Simple Java Solution but won,t pass on interviewBit compiler as only read 1st value of each row


#1

public int[][] diagonal(int[][] A) {

    int n=A.length;
    
int ans[][]=new int[n+n-1][];
int index=0;

/////simple diagonal
for(int x=0;x<n;x++){

    int size=0;
    /////////size getter
    int xx=x;
    
    for(int y=0;y<n && xx>=0;y++){
        size++;
        xx--;
    }
    ans[index]=new int[size];
    /////////put values now
    xx=x;
    for(int y=0;y<n && xx>=0;y++){
        ans[index][y]=A[y][xx];
        xx--;
    }
    index++;
}
///////////complex diagonal

for(int y=1;y<n;y++){

    int size=0;
    /////////size getter
    int yy=y;

    for( int x=n-1;x>=0 && yy<n;x--){
        size++;
        yy++;
    }
    ans[index]=new int[size];
    /////////put values now
    yy=y;
    int onlyhere=0;
    for(  int x=n-1;x>=0 && yy<n;x--){
        ans[index][onlyhere]=A[yy][x];
        yy++;
        onlyhere++;
    }

    index++;
}


return ans;
}