Merge Triplets to Form Target

Medium

Description

Given 2D array triplets and target triplet, determine if you can obtain target by taking maximum of each component from any triplets.

Examples

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

Take max from triplets 1 and 3.

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

For triplets = [[3,4,5],[4,5,6]], target = [3,2,5], the answer is false because the merge triplets to form target condition is not met.

Input:triplets = [[1,2,3],[4,1,6],[2,5,2]], target = [4,5,6]
Output:true
Explanation:

Form [4,5,6] by taking the maximum from all three triplets: max(1,4,2)=4, max(2,1,5)=5, max(3,6,2)=6.

Constraints

  • 1 ≤ triplets.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!