Matrix Madness - smallest non-negative number | PROGRAMMING INTERVIEWS
Question: There is an N x N matrix with the property that each entry in the matrix is the smallest non-negative number, which does not appear either above the entry or to its left. Write a method to find the entry in a particular row and column.
For example, for N=8, we might have the matrix:
0 1 2 3 4 5 6 71 0 3 2 5 4 7 62 3 0 1 6 7 4 53 2 1 0 7 6 5 44 5 6 7 0 1 2 35 4 7 6 1 0 3 26 7 4 5 2 3 0 17 6 5 4 3 2 1 0
Answer: From the question statement, it is clear that the top left corner starts things off with 0 and the top row and the leftmost column are each completed with the positive integers 1,2,3,..., in order.
Read full article from Matrix Madness - smallest non-negative number | PROGRAMMING INTERVIEWS
No comments:
Post a Comment