Computing the difference of the cross-totals of the diagonals of a matrix
How well/bad is this code written?


A good first timer implementation.


  Is the code abstract enough?


Mostly. It does make unnecessary assumptions about range.  It assumes int math does not overflow.

To make more abstract, code could use typedef int TVS_int; to ease future type changes.


  How can you solve such challenges more quickly?


Take advantage that the matrix is square.

With computing along the diagonal of a square matrix, only the matrix and its one size parameter are needed.

Use const to hint the the compiler about certain potential optimizations and convey code's intent better.

size_t is the best size of array indexing, not too wide nor too narrow.

I like the idea of using a wider intermediate type to mitigate overflow problems.

typedef int TVS_int;
typedef long long TVS_int2;  // a type with wider range.

TVS_int diagonalDifference_alt(const TVS_int** arr, size_t n) {
  TVS_int2 sum_up = 0;
  TVS_int2 sum_dn = 0;

  for (size_t i = 0; i&lt;n; i++) {
    // Notice both `arr` use the same `arr[i]` --&gt; potentially easier to optimize
    sum_up += arr[i][n-i-1];
    sum_dn += arr[i][i];
  }
  TVS_int2 diff = sum_up - sum_dn;
  return (TVS_int) ((diff &lt; 0) ? -diff : diff);  // OF possible here in range reduction 
}




if(left_to_right - right_to_left &gt; 0) unnecessarily incurs the potential for int overflow.  Simply compare instead.  if (left_to_right &gt; right_to_left)