/**
 * Given a square matrix as a nested map, return the elements on the diagonal using negative indexing.
 *
 * @param matrix The square matrix represented as a nested map.
 * @return A list containing the elements on the diagonal of the matrix.
 *
 * Example:
 * getMatrixDiagonal(mapOf(0 to mapOf(0 to 1, 1 to 2, 2 to 3), 1 to mapOf(0 to 4, 1 to 5, 2 to 6), 2 to mapOf(0 to 7, 1 to 8, 2 to 9)))
 * Output: [9, 5, 1]
 */
fun getMatrixDiagonal(matrix: Map<Int, Map<Int, Int>>): List<Int> {

    val diagonalElements = mutableListOf<Int>()

    for (i in matrix.keys) {
        diagonalElements.add(matrix[i]!![-(i + 1)]!!)
    }

    return diagonalElements
}
/**
 * Given a square matrix as a nested map, return the elements on the diagonal using negative indexing.
 *
 * @param matrix The square matrix represented as a nested map.
 * @return A list containing the elements on the diagonal of the matrix.
 *
 * Example:
 * getMatrixDiagonal(mapOf(0 to mapOf(0 to 1, 1 to 2, 2 to 3), 1 to mapOf(0 to 4, 1 to 5, 2 to 6), 2 to mapOf(0 to 7, 1 to 8, 2 to 9)))
 * Output: [9, 5, 1]
 */
fun getMatrixDiagonal(matrix: Map<Int, Map<Int, Int>>): List<Int> {
/**
 * Given a square matrix as a nested map, return the elements on the diagonal using negative indexing.
 *
 * @param matrix The square matrix represented as a nested map.
 * @return A list containing the elements on the diagonal of the matrix.
 *
 * Example:
 * getMatrixDiagonal(mapOf(0 to mapOf(0 to 1, 1 to 2, 2 to 3), 1 to mapOf(0 to 4, 1 to 5, 2 to 6), 2 to mapOf(0 to 7, 1 to 8, 2 to 9)))
 * Output: [9, 5, 1]
 */
fun getMatrixDiagonal(matrix: Map<Int, Map<Int, Int>>): List<Int> {

    val diagonalElements = mutableListOf<Int>()

    for (i in matrix.keys) {
        diagonalElements.add(matrix[i]!![-(i + 1)]!!)
    }

    return diagonalElements
}