Skip to content

In-Place 2D Transformation by Index Mapping

Problem

When you see matrix rotation or 2D in-place transformation

Strategy: In-Place 2D Transformation by Index Mapping

  • Think about this
    • Convert geometry into index mapping.
    • Ask whether the transform decomposes into simpler in-place steps:
      • transpose
      • reverse rows or columns
    • For square layers, think in cycles of 4 cells.
  • Avoid this
    • Do not allocate another matrix when in-place is required.
    • Do not mix up row reversal and column reversal.
    • Do not use shallow copies in tests for 2D arrays.
  • Tell this to the interviewer
    • Write the index mapping once.
    • Then show the decomposition into operations easier to implement safely.
  • See these problems