Skip to main content
2 of 2
Golfing suggestion.
Jonathan Frech
  • 7.5k
  • 1
  • 23
  • 44

C (gcc), 79 77 bytes

  • Saved two bytes thanks to Steadybox; only taking in one matrix dimension parameter as all matrices in this challenge are square.
j,i;f(A,n)int*A;{for(j=0;j<n*n;j++)printf("%d,",A[A[j]>A[i=j/n+j%n*n]?j:i]);} 

Try it online!

Takes a flat integer array A and the matrix dimension n (as the matrix has to be square) as input. Outputs a flat integer array string representation to stdout.

Jonathan Frech
  • 7.5k
  • 1
  • 23
  • 44