Merge Triplets to Form Target
MediumArrayMatrix
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:
trueExplanation:
Take max from triplets 1 and 3.
Input:
triplets = [[3,4,5],[4,5,6]], target = [3,2,5]Output:
falseExplanation:
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:
trueExplanation:
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⁵