Merge Triplets to Form Target Triplet
Choose any nonempty subset of triplets and take their coordinate-wise maximum. Return whether some such maximum equals target exactly.
Example 1
triplets = [[2,1,3],[1,4,2],[2,4,1]]
target = [2,4,3]trueExplanation
Taking maxima of [2,1,3] and [1,4,2] gives [2,4,3].
Example 2
triplets = [[3,1,1],[1,3,1]]
target = [2,2,1]falseExplanation
Each triplet exceeds a target coordinate, and maxima cannot lower it.
Example 3
triplets = [[1,2,3]]
target = [1,2,3]trueExplanation
The sole triplet already equals the target.
Constraints
- 1 <= number of triplets <= 100000
- Every triplet and target has three positive coordinates <= 1000
Function contract
mergeTripletsArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[2,1,3],[1,4,2],[2,4,1]][2,4,3]