Skip to content
Decoder

Merge Triplets to Form Target Triplet

Medium

Problem

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.

Example 1

Input
triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5]], target = [2, 7, 5]
Output
true
Why
merge the first and third

Example 2

Input
triplets = [[3, 4, 5], [4, 5, 6]], target = [3, 2, 5]
Output
false

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.