Back to problems

In-Place Sub-Matrix Move

Algorithm · Microsoft · Hard

Write move_rect(M, r1, c1, r2, c2, dr, dc, fill), which relocates a rectangular block of cells inside a matrix, working directly on that matrix. M is an $$R \times C$$ grid. The block to be moved is identified by its inclusive corners: the top-left corner (r1, c1) and the bottom-right corner (r2, c2). Once the call returns, that block's top-left corner must sit at (dr, dc), and M itself has to reflect the change — the routine returns nothing and no separate result matrix is…

Checking your access…