Top 150 InterviewEasy

Merge Triplets

Detailed guide and Python implementation for the 'Merge Triplets' problem.

Problem Statement

Easy

A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain. Return True if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or False otherwise.

Write a function mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool.

Constraints
  • 1 <= len(triplets) <= 10^5
  • triplets[i].length == target.length == 3
  • 1 <= ai, bi, ci, x, y, z <= 1000

Examples

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

Merge [2,5,3] and [1,7,5] to get [max(2,1), max(5,7), max(3,5)] = [2,7,5].

Example 2
Input
triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
Output
False
Explanation

Cannot get index 1 value of 2.

Need a Hint?
Consider using Greedy-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.