Different Neighours - An Interesting Matrix Problem

Greedy approach
Now grab a paper pen and start solving
try and draw a larger matrix like 10x10
you certainly can't find an error in such short matrix
@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.
@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
@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
@honeybuzz maximum value could be 4
@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?
@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
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
I am trying not to but I just can't find the damn pattern :/
Last edited on
try making a 10x10 maybe that would help
but I don't think that working through 100 cells by hand is a feasible option.
#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
/
Last edited on
@texo u can check it yourself from problem statement
you can also create a new program that will check if you matrix follows the rules or not yourself.
closed account (17o30pDG)
I have got 3 AC's but cannot think about the edge case can anyone give me a hint
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.