Different Neighours - An Interesting Matrix Problem

Jan 6, 2019 at 10:15am
Greedy approach
Now grab a paper pen and start solving
Jan 6, 2019 at 10:32am
try and draw a larger matrix like 10x10
you certainly can't find an error in such short matrix
Jan 6, 2019 at 3:40pm
@breaker your pattern is fine
break down the edge cases
eg. for n=2 m=2 answer would be
2
1 1
2 2
there are more edge cases
find them and handle
P.S please dont reveal your approach on the forum. The pattern is all u need to know in the problem and u have revealed it.
Jan 6, 2019 at 5:33pm
@breaker but the pattern of the row is breaking when we have 2 rows and 5 columns.
Here the answer would be
1 1 2 2 3
2 2 3 3 1
Jan 6, 2019 at 6:18pm
@breaker is the pattern for the remaining cells related to the values of the cell that we have already found or is it something else as I cannot find any pattern for the other cell values. I have created an algorithm and have tried it for all values between 1<=n,m<=50(generated using another python script) and the maximum value of k that I am getting is 5.Is it correct?
Last edited on Jan 6, 2019 at 6:19pm
Jan 6, 2019 at 6:23pm
@honeybuzz maximum value could be 4
Jan 6, 2019 at 6:26pm
@blackmamba that's what I was thinking but I just cannot create a matrix for even 5x5 without the maximum value being 5.

This is what my current code is giving me for 5x5

1 1 2 2 1
2 3 3 4 1
2 4 1 5 2
1 4 2 3 3
1 3 2 1 1

Can you tell me how can we create this matrix in maximum of 4 different values?
Jan 6, 2019 at 6:39pm
@honeybuzz the algorithm you made is as good as your approach to the problem
i see that you trying to minimise number in every cell as you go on....that is why your algo is failing
in cell (2,5) try putting 4 instead of 1 and u will see
Jan 6, 2019 at 7:00pm
So my current algorithm won't work. I can see that the correct answer to 5X5 is
1 1 2 2 1
2 3 3 4 4
2 4 1 1 2
1 4 2 3 3
1 3 2 4 1

I can see that if n>=3 and m>=3 then we would always need 4 different values. However, considering the above arrangement, I cannot see any pattern so that I can relate a cell (x,y) with the other cells. The only thing I can see is that using 2 same values in consecutive cells row wise is sort of beneficial to minimize the values.
For example in the 2nd row --> we have two 3's and 2 4's together.
in the 3rd row we have two 1's together and so on.
However, there is no relationship as to which values would be repeated.
Last edited on Jan 6, 2019 at 8:53pm
Jan 6, 2019 at 7:41pm
I am trying not to but I just can't find the damn pattern :/
Last edited on Jan 6, 2019 at 7:41pm
Jan 6, 2019 at 7:51pm
try making a 10x10 maybe that would help
Jan 6, 2019 at 8:45pm
but I don't think that working through 100 cells by hand is a feasible option.
Jan 7, 2019 at 9:15am
#blackmamba
Can you tell me if the pattern needed to find is present in this matrix or not?
1 1 2 2 1
2 3 3 4 4
2 4 1 1 2
1 4 2 3 3
1 3 2 4 1
Jan 9, 2019 at 3:34am
/
Last edited on Jan 9, 2019 at 2:55pm
Jan 9, 2019 at 5:29am
@texo u can check it yourself from problem statement
Jan 9, 2019 at 5:56am
you can also create a new program that will check if you matrix follows the rules or not yourself.
Jan 13, 2019 at 10:58am
closed account (17o30pDG)
I have got 3 AC's but cannot think about the edge case can anyone give me a hint
Jan 13, 2019 at 11:03am
closed account (17o30pDG)
I got 3 AC's can anyone help me with edge case, give me a hint if possible
Topic archived. No new replies allowed.