Spiral Matrix

Given a 2D Matrix of order n X m , print Kth element in spiral form of matrix. See the following examples. 
INPUT 
Each test case starts with a number N, the size of the matrix(n*m). The next line contains the n*m numbers. The next number contains kth number. 
OUTPUT 
Prints the kth element. Constraints: If n or m is less than 1 , return -1; 

Example: 
Input: 
mat[][] = {{1, 2, 3, 4, 5, 6} {7, 8, 9, 10, 11, 12} {13, 14, 15, 16, 17, 18}} 
k = 17 
Output
10

CODE

Comments

Popular posts from this blog

Female co passenger hack

C library function - qsort()

Wildcard Pattern Matching (DP)