LeetCode Entry

867. Transpose Matrix

10.12.2023 easy 2023 kotlin

Transpose 2D matrix

867. Transpose Matrix easy blog post substack youtube image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/434

Problem TLDR

Transpose 2D matrix

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(n)\)

Code


  fun transpose(matrix: Array<IntArray>): Array<IntArray> =
    Array(matrix[0].size) { x ->
      IntArray(matrix.size) { y ->
        matrix[y][x]
      }
    }