How to Create a matrix of N*N with sum of every ith row and every ith column combined equals to a specific sum? This problem was asked to me in an interview round and was told to just tell the logic!
all the elements in row and column combined should be distinct
For Eg: There is an N=2 and Sum=6
A matrix [3,1]
         [2,3]
satisfies the given condition where 1st Row and 1st column add upto 3+1+2=6 same happens for the second row.
 A: $$\left[\begin{matrix}0&1&2&\ldots&n-1\\-1&0&1&\cdots&n-2\\-2&-1&0&\cdots&n-3\\\vdots&\vdots&\vdots&&\vdots\\-(n-1)&-(n-2)&-(n-3)&\cdots&0\end{matrix}\right]$$
This matrix has the desired property and all the sums are $0$. If you want all sums to be $N$, simply add $\frac{N}{2n-1}$ to all elements of the matrix.
A: Pick suitable $b_i$ and $c_j$, and set $a_{i,j}=b_i+c_j$ whenever $i\ne j$. Then adjust $a_{i,i}$ to match the desired sum $S$.
For a concrete example, start with 
$$\begin{pmatrix}0&1&2&\cdots &n-1\\n&n+1&n+2&\cdots&2n-1\\2n&2n+1&2n+2&\cdots&3n-1\\\vdots&\vdots&\vdots&\ddots&\vdots\\n^2-n&n^2-n+1&n^2-n+2&\cdots& n^2-1\end{pmatrix}, $$
which almost solves the problem: All entries in row $i$ and column $i$ together are distinct (in fact, all entries of the matrix are distinct).
However, the sum of elements in row $i$ (starting indexing from $0$) is 
$$in+(in+1)+(in+2)+\cdots+(in+n-1)=in^2+\frac{n(n-1)}2,$$
the sum of the elements in column $i$ is
$$i +(n+i)+(2n+i)+\cdots+((n-1)n+i)=\frac{n^2(n-1)}2+ni,$$
so that the sum over row and column is
$$ (n^2+n)i+\frac{(n^2+n)(n-1)}2-(n+1)i=\frac{n^3-n}2+(n^2-1)i.$$
If we replace diagonal elements with other numbers $a_{i,i}$, this becomes
$$ \frac{n^3-n}2+(n^2-n-2)i+a_{i,i}.$$
Hence our goal is to make $$a_{i,i}=S-(n^2-n-2)i.$$
Depending on $S$, some $a_{i,i}$ may become equal to some $a_{i,j}$ or $a_{j,i}$, but in total this forbids at most $n\cdot 2(n-1)$ values of $S$. 
