Not working, but alg in place

For some reason the algorithm is giving the correct results but it is not populating the result matrix correctly. Need to debug