Question is nothing but store all diagonal(principal as well as anti diagonal) element in an array. So total n diagonal + n-1 anti diagonal element. we have to store total 2n-1element. Array size should be 2n-1 but starting from 0 It will go upto 2n-1. Final array is something like A[0.1.2........2n-2].
now question,
If (i==j) return (A[i-1]) ...... //Principal diagonal
Else if (i+j == n+1) return A[n+i-1] //Anti-digonal