MediumGreedy · Arrays

Merge Triplets to Form Target

You may repeatedly pick two triplets and replace one with their element-wise max. Return true if target = [x, y, z] can end up as one of the triplets.

triplets = [[1,2,3],[7,1,1]], target = [7,2,3] → truetriplets = [[2,5,6],[1,4,4],[5,7,5]], target = [5,4,6] → false

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

Triplets

Gold slots = target positions matched exactly by a safe triplet

Time and space complexity

n = number of triplets. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Up to 10 triplets, values from 1 to 100.