I'm confused. In the first row the value 2 has a neighbor that is also 2. And in the second row, the value 3 has a neighbor that is also 3. What am I missing?
You have to make sure that the immediate neighbours of each cell are different.
It doesn't matter what the value is in the cells whose neighbours you are checking.
Hence, if we are checking for cell (x,y), then we have to make sure that the value in (x+1,y), (x-1, y), (x,y+1) and (x,y-1) are distinct. We don't care for the value in cell (x,y) is. We have to do this for all the cells in the matrix i.e for all i<=x<=n and 1<=x<=m.
@FurryGuy I am not looking for the code. I don't want the code. I am just unable to find the pattern in the rows and columns. I observed that the first row could be 1 1 2 2 1 1 .... always but its failing for n = 2 and m = 5 where the optimal choice would be
1 1 2 2 3
2 3 3 1 1
What are you saying?If I don't even know the algorithm to a question then how/why am I supposed to code it? How can I code an algorithm when I don't even know it. I am currently working through it on pen and paper.
its obviously not the most efficient way to solve the problem. The maximum value could be 4. Hence, we need to design an algorithm that can create the matrix using only 1,2,3 and 4.
@shinjikagava there are already enough hints in the forum.
If u want direct solution to a problem then that is not going to happen.
And if u want to learn then hints already provided are enough.
Give it some time and work on it.
so should i binary search for min value of k for or fill with greedy heuristics?
is there some hidden observation that i am missing?
can someone give me some momentum so that i can code it.
i am getting 5 as max value of k.