Le migliori 150 intervisteFacile

Unisci triplette

Guida dettagliata e implementazione Python per il problema 'Unisci triplette'.

Dichiarazione del problema

Facile

Una tripletta è un array di tre numeri interi. Ti viene fornito un array di triplette di interi 2D, dove triplette[i] = [ai, bi, ci] descrive la i-esima tripletta. Ti viene anche fornito un target di array di numeri interi = [x, y, z] che descrive la tripletta che desideri ottenere. Restituisce True se è possibile ottenere la tripletta target [x, y, z] come elemento di triplette, oppure False altrimenti.

Scrivi una funzione mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool.

Vincoli
  • 1 <= len(triplets) <= 10^5
  • triplets[i].length == target.length == 3
  • 1 <= ai, bi, ci, x, y, z <= 1000

Esempi

Example 1
Input
triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
Output
True
Explanation

Merge [2,5,3] and [1,7,5] to get [max(2,1), max(5,7), max(3,5)] = [2,7,5].

Example 2
Input
triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
Output
False
Explanation

Cannot get index 1 value of 2.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Greedy 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.