Python Nozioni di baseFacile

Elemento più grande in un array

Guida dettagliata e implementazione Python per il problema "L'elemento più grande in un array".

Dichiarazione del problema

Facile

Scrivi una funzione find_largest(arr) che trovi e restituisca l'elemento più grande nell'array dato arr utilizzando la ricorsione. La funzione accetta un elenco di numeri interi come input e restituisce un singolo numero intero, il valore massimo nell'elenco.

Vincoli
  • 1 <= len(arr) <= 1000
  • -10^6 <= arr[i] <= 10^6

Esempi

Example 1
Input
arr = [1, 4, 3, -5, 15]
Output
15
Explanation

Among all elements, 15 is the largest.

Example 2
Input
arr = [10, 20, 5, 8]
Output
20
Explanation

20 is the maximum value in the array.

Example 3
Input
arr = [-3, -7, -1, -9]
Output
-1
Explanation

Among all negative numbers, -1 is the largest.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche della ricorsione 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.