Python Nozioni di baseFacile

Invertire una matrice

Guida dettagliata e implementazione Python per il problema "Inverti un array".

Dichiarazione del problema

Facile

Scrivi una funzione reverse_array(arr) che accetta una lista di numeri interi arr e restituisce una nuova lista con gli elementi in ordine inverso. Ad esempio, [1, 2, 3] diventa [3, 2, 1].

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

Esempi

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

The elements are reversed: first becomes last and last becomes first.

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

Two elements swapped.

Example 3
Input
arr = [7]
Output
[7]
Explanation

Single element array reversed is the same.

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.