Tap here to switch tabs
Problem
Submissions

Problem: Merge Triplets to Form Target Triplet

med
30 min
Try to solve the Merge Triplets to Form Target Triplet problem.

Statement

You are given a 2extD2 ext{D} integer array triplets, where triplets[i] =[ai,bi,ci]= [a_i, b_i, c_i] describes the iextthi^{ ext{th}} triplet, and an integer array target =[x,y,z]= [x, y, z] representing the desired target triplet.

You can perform the following operation any number of times:

  • Select two distinct indices i and j (0≤i,j<0 \leq i, j < triplets.length) and update triplets[j] to become [max⁡(ai,aj),max⁡(bi,bj),max⁡(ci,cj)][\max(a_i, a_j), \max(b_i, b_j), \max(c_i, c_j)].

Return true if it is possible to make target an element of triplets, or false otherwise.

Constraints:

  • 1≤1 \leq triplets.length ≤105\leq 10^5

  • triplets[i].length ==== target.length ==3== 3

  • 1≤ai,bi,ci,x,y,z≤10001 \leq a_i, b_i, c_i, x, y, z \leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Merge Triplets to Form Target Triplet

med
30 min
Try to solve the Merge Triplets to Form Target Triplet problem.

Statement

You are given a 2extD2 ext{D} integer array triplets, where triplets[i] =[ai,bi,ci]= [a_i, b_i, c_i] describes the iextthi^{ ext{th}} triplet, and an integer array target =[x,y,z]= [x, y, z] representing the desired target triplet.

You can perform the following operation any number of times:

  • Select two distinct indices i and j (0≤i,j<0 \leq i, j < triplets.length) and update triplets[j] to become [max⁡(ai,aj),max⁡(bi,bj),max⁡(ci,cj)][\max(a_i, a_j), \max(b_i, b_j), \max(c_i, c_j)].

Return true if it is possible to make target an element of triplets, or false otherwise.

Constraints:

  • 1≤1 \leq triplets.length ≤105\leq 10^5

  • triplets[i].length ==== target.length ==3== 3

  • 1≤ai,bi,ci,x,y,z≤10001 \leq a_i, b_i, c_i, x, y, z \leq 1000