Merge Triplets to Form Target Triplet
Part of Practice: Clever Commitments
You are given a list of triplets (arrays of three integers) and a target triplet. In one operation you pick two triplets you have and replace one of them with their element-wise maximum — position by position, keep the larger value. You may repeat this any number of times using the original and merged triplets. Return true if some sequence of operations can produce a triplet exactly equal to target.
Constraints that matter: up to 100,000 triplets, and merging only ever raises values, never lowers them — that irreversibility is the heart of the problem.
Examples
- Input:
- triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
- Output:
- true
Merge [2,5,3] with [1,7,5]: element-wise max is [2,7,5], which equals the target in one operation.
- Input:
- triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
- Output:
- false
Every triplet has a middle value larger than 2, and taking maximums can never lower a value back down to 2.
- Input:
- triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]
- Output:
- true
Merging [2,5,3], [1,2,5], and [5,2,3] together yields [5,5,5].
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.