Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Merge Triplets to Form Target Triplet

Medium

Topics
ArrayGreedy

You are given triplets and a target triplet. A merge replaces the running triplet with the element-wise maximum of it and a chosen triplet. Return true if some sequence of merges can produce exactly target.

Example 1

Input:  triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
Output: true

Example 2

Input:  triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
Output: false

Constraints

  • 1 <= triplets.length <= 10^5
  • triplets[i].length == target.length == 3
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access