LeetCode Entry

1582. Special Positions in a Binary Matrix

13.12.2023 easy 2023 kotlin

#### Join me on Telegram

1582. Special Positions in a Binary Matrix easy blog post substack image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/437

Complexity

  • Time complexity: \(O((nm)^2)\)

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

Code


    fun numSpecial(mat: Array<IntArray>): Int {
       var count = 0
       for (y in 0..mat.lastIndex)
        for (x in 0..mat[y].lastIndex)
          if (mat[y][x] == 1
            && (0..mat.lastIndex).filter { it != y }.all { mat[it][x] == 0}
            && (0..mat[y].lastIndex).filter { it != x }.all { mat[y][it] == 0})
              count++
       return count
    }