Create a matrix of size m x n so that the neighbours of each cell have distinct values and the max value in this matrix is min

Pages: 12
Jan 6, 2019 at 1:35pm
Write your question here.

Example -
if n = 2 and m = 3:
1 1 2
2 3 3

Here every immediate neighbour of each cell has distinct values and the maximum value used in this matrix is 3.
Last edited on Jan 6, 2019 at 7:14pm
Jan 6, 2019 at 2:17pm
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?
Jan 6, 2019 at 5:02pm
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.
Jan 6, 2019 at 5:07pm
closed account (E0p9LyTq)
So, are you wanting us to write the program for you? Not going to happen.

Write code that you think meets the requirement. Post that and we can give you advice if it doesn't do what you want.
Jan 6, 2019 at 5:10pm
@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
Jan 6, 2019 at 5:16pm
closed account (E0p9LyTq)
So you want an algorithm handed to you without showing you have tried to create a solution on your own.

If you have written some code, post it.
Jan 6, 2019 at 5:18pm
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.
Jan 6, 2019 at 6:34pm
@honeybuzz for n=2 m=3 you wrote
1 2 2
2 3 3
this is wrong as 1 has neighbours 2 and 2
Jan 6, 2019 at 7:15pm
@blackmamba fixed it.
Jan 7, 2019 at 3:07am
Thanks for the explanation. I understand the problem now. I don't know why these posts were reported.

Hmm. It's an interesting problem.

One way to get unique neighbors is like so:

Row1: 1 4 7 1 4 7 1 4 7 ...
Row 2: 2 5 8 2 5 8 2 5 8 ...
Row 3: 3 6 9 3 6 9 3 6 9 ...

But will this give the minimum max value? I don't know.
Jan 7, 2019 at 8:58am
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.
Jan 7, 2019 at 9:10am
@dhayden A much better way to do so would have been
1 1 2 2 1 1 2 2 1 1
2 3 3 4 4 3 3 4 4 2
2 4 1 1 2 2 1 1 3 2

But I can't see any pattern here
Jan 7, 2019 at 12:20pm
..
Last edited on Jan 7, 2019 at 2:06pm
Jan 7, 2019 at 2:03pm
handle those cases differently.
thats where if else statements come into use
Jan 7, 2019 at 2:06pm
@blackmamba thanx
i just got 100 points
Jan 7, 2019 at 4:49pm
Oh, I thought the diagonal neighbors counted too.
Jan 7, 2019 at 6:13pm
@dhayden NVM I got it correct ;)
Jan 7, 2019 at 9:15pm
@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.
Jan 9, 2019 at 10:01pm
its not optimal
Jan 9, 2019 at 10:32pm
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.
Last edited on Jan 9, 2019 at 10:43pm
Pages: 12