Sekcja DSAŁatwe

Kolejka przy użyciu stosu

Szczegółowy przewodnik i implementacja Python dla problemu „Kolejka używająca stosu”.

Oświadczenie o problemie

Łatwe

Napisz funkcję execute_queue_using_stacks(operations), która symuluje kolejkę przy użyciu dwóch stosów. Dane wejściowe to lista krotek operations, gdzie każda krotka to ("enqueue", val) lub ("dequeue",). Zwróć listę wartości usuniętych z kolejki.

Ograniczenia
  • 0 <= len(operations) <= 1000

Przykłady

Example 1
Input
operations = [("enqueue", 1), ("enqueue", 2), ("dequeue",), ("enqueue", 3), ("dequeue",)]
Output
[1, 2]
Explanation

Enqueued elements are retrieved in FIFO order using LIFO stack operations.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla kolejek, 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.