Sekcja DSAŁatwe

Połącz tablice

Szczegółowy przewodnik i implementacja Python dla problemu „Scal tablice”.

Oświadczenie o problemie

Łatwe

Napisz funkcję merge_sorted_arrays(arr1, arr2), która pobiera dwie posortowane tablice liczb całkowitych arr1 i arr2 i łączy je w jedną posortowaną tablicę, która jest zwracana.

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

Przykłady

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?
Rozważ użycie struktur danych specyficznych dla tablic, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

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

Otwórz w Edytorze
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

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.