Skip to content

Merge Triplets to Form Target Triplet

MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.

You have a list of triplets, each [a, b, c], and a target triplet. One operation picks two triplets and replaces one of them with their element-wise maximum: [max(a1, a2), max(b1, b2), max(c1, c2)]. You may do this any number of times. Return true if target can appear in the list.

triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5]], target = [2, 7, 5]  →  true    (merge the first and third)
triplets = [[3, 4, 5], [4, 5, 6]],            target = [3, 2, 5]  →  false

Constraints

  • 1 <= triplets.length <= 10^5
  • triplets[i].length == target.length == 3
  • 1 <= a, b, c, target[j] <= 1000