Skip to content

Instantly share code, notes, and snippets.

@enzobonggio
Last active January 8, 2022 03:21
Show Gist options
  • Save enzobonggio/be4d603e2704d22f8f1312de99542096 to your computer and use it in GitHub Desktop.
Save enzobonggio/be4d603e2704d22f8f1312de99542096 to your computer and use it in GitHub Desktop.

Task

Se te da una matriz de numeros. En una "matriz montaña" la diferencia entre dos numeros adyacentes (ortogonalmente o diagonalmente) no es mas grande que 1. Un cambio consiste en incrementar un numero de la matriz en 1. Tu tarea es transformar la matriz inicial en una "matriz montaña" con menor cantidad de cambios

Examples

to_mountain([[2, 2, 1, 2],
            [1, 0, 2, 1],
            [1, 0, 1, 2],
            [1, 2, 2, 1]])
# returns: [[2, 2, 1, 2],
#           [1, 1, 2, 1],
#           [1, 1, 1, 2],
#           [1, 2, 2, 1]]

to_mountain([[2, 2, 1, 2],
             [1, 0, 2, 1],
             [1, 0, 1, 2],
             [1, 2, 2, 4]])
# returns: [[2, 2, 1, 2],
#           [1, 2, 2, 2],
#           [1, 2, 3, 3],
#           [1, 2, 3, 4]]

Constraints

0 < len(matrix) <= 100 0 < len(matrix[0]) <= 100 0 <= n <= 1e9 y n es un entero por cada numero de la matriz

Tests

8 tests harcodeados and 126 test con valores aleatorios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment