LeetCode Entry

Toeplitz Matrix

31.10.2022 easy 2022 kotlin

just compare adjacent rows, they must have an equal elements except first and last

https://leetcode.com/problems/toeplitz-matrix/ easy

Solution [kotlin]


    fun isToeplitzMatrix(matrix: Array<IntArray>): Boolean =
        matrix
        .asSequence()
        .windowed(2)
        .all { (prev, curr) -> prev.dropLast(1) == curr.drop(1) }

Explanation: just compare adjacent rows, they must have an equal elements except first and last