Diagonal Difference

  • + 0 comments

    in C

    int diagonalDifference(int arr_rows, int arr_columns, int** arr) {
        
        int LTRsum = 0, RTLsum = 0;
        
        for(int r=0,c=0;r<arr_rows && c<arr_columns;r++,c++){
                        
                    /*LTR*/
                    LTRsum+=arr[r][c];
                    /*RTL*/
                    RTLsum+= arr[r][arr_columns-1-c];
                
        }
        
        if((RTLsum-LTRsum) >= 0){
            return RTLsum-LTRsum;
        }else {
        return  LTRsum-RTLsum;
        }
    }