Sezione DSAFacile

Triplette pitagoriche

Guida dettagliata e implementazione Python per il problema delle 'triplette pitagoriche'.

Dichiarazione del problema

Facile

Scrivi una funzione contains_pythagorean_triplet(arr) che accetta un array di numeri interi positivi arr e restituisce True se ci sono tre numeri interi a, b e c nell'array tale che a^2 + b^2 = c^2 o False in caso contrario.

Vincoli
  • 3 <= len(arr) <= 1000
  • 1 <= arr[i] <= 1000

Esempi

Example 1
Input
arr = [3, 1, 4, 6, 5]
Output
True
Explanation

3^2 + 4^2 = 9 + 16 = 25 = 5^2.

Example 2
Input
arr = [10, 4, 6, 12, 5]
Output
False
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.