Can anyone help me finding the pattern? I tried for some times. But nothing came to my head.!

Finding the matrix pattern.
-
0Take a look at the numbers and the sizes of the number squares. After that, you take a look at the symmetry of the output. – 2017-01-10
-
0Can you please elaborate? I actually don't get it,what do you mean by symmetry? – 2017-01-10
-
0Take a look at the last example (the one belonging to 5). You can see, that the outer rim is always filled with 1, while there is no other 1 in there. After that, you look at the 2's and how they are arranged. – 2017-01-10
-
0Thanks boss! Found the way! :) – 2017-01-10
3 Answers
The value of each cell of the matrix is equal to the Manhattan distance from the cell to the closest border $+1$.
The numbers represent the distance of an element to the nearest border, ie. for a matrix $n\times n$ the value of element $a_{i,j}$ $(i,j \in \{1,2,...,n\})$ is
$$a_{i,j} = \min (i, n-i+1, j, n-j+1)$$
Basically an input of $n $ gives us a $n\times n $ matrix where the first and last row and column elements are $1$. We then get an inner $(n-2)\times (n-2) $ matrix. The first and last row and column elements are filled with $2$. The process keeps repeating. We can thus say that $a_{ij} =\operatorname {min}(i, n-i+1, n-j +1)$.
Also note that the elements of this $n\times n $ matrix for an input $n $ contains elements in the set $\{1,2,\cdots, \lceil \frac {n}{2} \rceil \} \in \mathbb N $. Hope it helps.