Python Conceptos básicosfácil

Encontrar el elemento más pequeño en una matriz

Guía detallada e implementación de Python para el problema 'Buscar el elemento más pequeño en una matriz'.

Declaración del problema

fácil

Escribe una función find_smallest(arr) que tome una lista de números enteros arr y devuelva el elemento más pequeño. Itere a través de la matriz y realice un seguimiento del valor mínimo visto hasta ahora.

Restricciones
  • 1 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Ejemplos

Example 1
Input
arr = [3, 7, 2, 8, 1]
Output
1
Explanation

Comparing all elements: 3, 7, 2, 8, 1. The minimum is 1.

Example 2
Input
arr = [-5, -2, -8, -1]
Output
-8
Explanation

Among negative numbers, -8 is the smallest.

Example 3
Input
arr = [42]
Output
42
Explanation

Only one element, so it is the smallest.

Need a Hint?
Considere la posibilidad de utilizar estructuras de datos específicas de matrices, como conjuntos o montones.
Edge Cases to Watch
  • Estructuras de entrada vacías
  • Entradas de un solo elemento
  • Grandes límites numéricos

¿Listo para resolver?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Abrir en el editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Recursos recomendados de Python

Amplíe sus conocimientos con tutoriales interactivos relacionados, hojas de trucos y comparaciones de códigos.