Merge Triplets to Form Target Triplet

Medium

Topics
ArrayGreedy

You are given triplets and a target triplet. A merge replaces the running triplet with the element-wise maximum of it and a chosen triplet. Return true if some sequence of merges can produce exactly target.

Example 1

Input:  triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
Output: true

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
Run ⌘' · Submit ⌘⏎