Programmazione competitivaFacile

Somma sottoinsieme

Guida dettagliata e implementazione Python per il problema "Somma dei sottoinsiemi".

Dichiarazione del problema

Facile

Scrivi una funzione is_subset_sum(arr, total) che restituisca True se esiste un sottoinsieme di interi non negativi in arr la cui somma è total e False altrimenti.

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

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche della programmazione dinamica 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.