Back to Practice Dashboard
Top 150 InterviewEasy

Merge Triplets

Learn how to solve the 'Merge Triplets' problem. This detailed resource details brute force and optimized approaches.

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?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

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

Open in Editor