Programowanie konkurencyjneŁatwe

Suma podzbioru

Szczegółowy przewodnik i implementacja Python dla problemu „Suma podzbioru”.

Oświadczenie o problemie

Łatwe

Napisz funkcję is_subset_sum(arr, total), która zwraca True, jeśli istnieje podzbiór nieujemnych liczb całkowitych w arr, którego suma wynosi total, lub False w przeciwnym razie.

Ograniczenia
  • 1 <= len(arr) <= 100
  • 0 <= arr[i] <= 1000
  • 0 <= total <= 10000

Przykłady

Example 1
Input
is_subset_sum([3, 34, 4, 12, 5, 2], 9)
Output
True
Explanation

The subset {4, 5} sums to 9.

Example 2
Input
is_subset_sum([3, 34, 4, 12, 5, 2], 30)
Output
False
Explanation

No subset sums to 30.

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