CodeArchon

mediumGreedyAmazon

Target Triple Composer

A sculpting robot picks any triplets whose coords ≤ target, taking element-wise max; can it hit the exact target triplet?

Given a list of triplets and a target triplet, decide if element-wise maximums of a chosen subset can equal target. Triplets whose any component exceeds target are useless.

Choose approach

2
0
7
1
5
2
Setfound
0:✓
1:·
2:·
1/4
Narrationstep 1 of 4

Triplet [2,5,3] accepted. found=[true,false,false].

1def mergeTriplets(triplets, target):
2 found = [False, False, False]
3 for t in triplets:
4 if t[0] > target[0] or t[1] > target[1] or t[2] > target[2]: continue
5 for i in range(3):
6 if t[i] == target[i]: found[i] = True
7 return all(found)
Variables
r=0
found=true,false,false
rejected=false

How to think about it

  1. Max is monotone -> any valid-size triplet is safe to use.
  2. Need at least one triplet to supply each coordinate's target.

Edge cases to catch in interview

  • No valid triplets -> false.
  • Target already appears as a triplet -> true.

Examples

Example 1false
{"triplets":[[3,4,2],[4,2,4],[3,3,2]],"target":[3,2,5],"values":[3,2,5]}

Try your own input

SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed