Sezione DSAFacile

Unisci array

Guida dettagliata e implementazione Python per il problema "Unisci array".

Dichiarazione del problema

Facile

Scrivi una funzione merge_sorted_arrays(arr1, arr2) che accetta due array di interi ordinati arr1 e arr2 e li unisce in un unico array ordinato, che viene restituito.

Vincoli
  • 0 <= len(arr1), len(arr2) <= 10^4
  • -10^9 <= arr1[i], arr2[j] <= 10^9

Esempi

Example 1
Input
arr1 = [1, 3, 5], arr2 = [2, 4, 6]
Output
[1, 2, 3, 4, 5, 6]
Explanation

We merge elements from both arrays sequentially preserving the sorted order.

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.