A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [a_i, b_i, c_i] describes the i-th triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain. To obtain target, you may apply the following operation on triplets any number of times: choose two indices i and j and update triplets[j] to [max(a_i, a_j), max(b_i, b_j), max(c_i, c_j)]. Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.
Example 1
Input: triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
Output: true
Explanation: [1,8,4] has 8 > 7, so using it would overshoot the target and it must be skipped. Merging the other two, [2,5,3] and [1,7,5], takes the maximum in each position and gives [2,7,5], the target.
Example 2
Input: triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
Output: false
Explanation: The target's middle value is 2, but every triplet has a middle value above 2 (4 and 5). Any merge would overshoot, so the target cannot be formed.
Example 3
Input: triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]
Output: true
Explanation: Every triplet stays at or below 5 in each position. [5,2,3] supplies the first 5, [2,5,3] the second and [1,2,5] the third, so merging them gives [5,5,5].
Since merging only takes maximums, a triplet that exceeds the target in any position can never be used (it would overshoot). Among the safe triplets, we just need each target position to be matched exactly by at least one.
Run checks all cases above. Submit evaluates all test cases.