@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 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?
@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.