Python Nozioni di baseFacile

Trova l'elemento più piccolo in una matrice

Guida dettagliata e implementazione Python per il problema "Trova l'elemento più piccolo in un array".

Dichiarazione del problema

Facile

Scrivi una funzione find_smallest(arr) che accetta un elenco di numeri interi arr e restituisce l'elemento più piccolo. Scorri l'array e traccia il valore minimo visto finora.

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

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche degli array come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.